Page 1 of 1 1
Topic Options
#189070 - 2008-08-11 10:05 AM IF ELSEIF ENDIF workaround
Daeseleer Offline
Fresh Scripter

Registered: 2008-08-01
Posts: 8
Hello all.

I am new to KiXtart scripting so I have a basic question/problem...

First here is the code:

 Code:
If InGroup("Group1")
  $Out = "Forced database to: Kroon Users" 
  $x = WriteLine (9 , $tab + $Out + @CRLF )
  $dbini = ReadProfileString($datafile, "Databases","Group1")
  $basisshare = $datashare + "\map\map1"
EndIf
If InGroup("Group2")
  $Out = "Forced database to: Kroon dealerdatabase"
  $x = WriteLine (9 , $tab + $Out + @CRLF )
  $dbini = ReadProfileString($datafile, "Databases","Group2")
  $basisshare = $datashare + "\map\map2"
  $usergroup = "Usergroup"
  $Force = "CT70"
Else
  $Out = "Forced database to: Kroon Users/Kroon dealerdatabase - No Permissions!!!"
  $x = WriteLine (9 , $tab + $Out + @CRLF )
  $Out = "Rolling back ini update (if any)."
  $x = WriteLine (9 , $tab + $Out + @CRLF )
  $error = WriteProfileString ($userfile, "Stations", $StationUsers[$FirstEmpty,1], " ")
  If $error <> 0
    $Out = "Error writing to " + $userfile + ", quitting script"
    $x = WriteLine (9 , $tab + $Out + @CRLF )
  EndIf
  Goto End
EndIf


As you can see there are 2 IF statements. Now the script doesn't execute as I want it to. Users only member of the Group1 do not connect to the right database because the 2nd IF statement is also executed and because they are not member of Group2 they are forced to End.(because of the Goto End statement.

I have little programming experience and in other languages you could use the ELSEIF statement.
That way there would be more options to use. But in KiXtart the ELSEIF doesn't work...(or I am programming it the wrong way).
Is there another way to handle this problem?
Do I need to use a SELECT here to get the right group for the users?

I hope you understand what I am trying to explain.
Thanks in advance.

Daeseleer


Edited by Daeseleer (2008-08-11 10:22 AM)

Top
#189072 - 2008-08-11 11:27 AM Re: IF ELSEIF ENDIF workaround [Re: Daeseleer]
Daeseleer Offline
Fresh Scripter

Registered: 2008-08-01
Posts: 8
As I asked in my previous post I have tried to do it with a SELECT.
I have tested it and it seems to work fine!

Is it a correct way to use? Or are there other better options?

Best regards,

Daeseleer

Top
#189076 - 2008-08-11 11:59 AM Re: IF ELSEIF ENDIF workaround [Re: Daeseleer]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4314
Loc: New Jersey
Yes, Select is the appropriate choice - it's like a multiple if statement, but only one choice is made. The thing to keep in mind with Select is the proper ordering of the comparisons. You might also need to employ AND or OR logic, so it takes a bit of extra planning.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#189077 - 2008-08-11 12:02 PM Re: IF ELSEIF ENDIF workaround [Re: Daeseleer]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4653
Loc: The Netherlands
Kix does not have and ElseIf statement but it does have an Else statement so you could do something like shown below.

 Code:
If $x = "1"
	;Do stuff
Else
	;Do other stuff
EndIf
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#189078 - 2008-08-11 12:36 PM Re: IF ELSEIF ENDIF workaround [Re: Mart]
Daeseleer Offline
Fresh Scripter

Registered: 2008-08-01
Posts: 8
Indeed,

But, in my case, if u need more then 2 options the IF-ELSE-ENDIF is not enough.
Thanks for your replies.

Daeseleer

Top
#189080 - 2008-08-11 02:05 PM Re: IF ELSEIF ENDIF workaround [Re: Daeseleer]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4499
Loc: USA
Select is the way to go... but else if is an option, just not with elseif ;\)

 Code:
If $x = "1"
	;Do stuff
Else
  if $y= 1
	;Do other stuff
  else
        ;Do fun stuff
  endif
EndIf

Top
#189081 - 2008-08-11 09:37 PM Re: IF ELSEIF ENDIF workaround [Re: Allen]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11590
Loc: CA
And even Allen's example can also be placed within a SELECT CASE making it quite versatile scripting.
Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 170 anonymous users online.
Newest Members
tspirtle, Safio, Eldonbetz, mgreene, DerekP
17716 Registered Users

Generated in 0.066 seconds in which 0.023 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org