Page 1 of 1 1
Topic Options
#201680 - 2011-03-02 12:03 AM IF..ELSE...ENDIF Limitation?
AshishS Offline
Fresh Scripter

Registered: 2008-10-27
Posts: 20
How many times can you have ELSE statements in Kix? More specifically, is there a limit?
Instead of doing this....
IF @USERID = "GEN1"
AddPrinterConnection("\\PRINTSERVER\HP PRINTER")
ELSEIF @USERID = "GEN2"
AddPrinterConnection("\\PRINTSERVER\HP PRINTER 2")
ENDIF

Can I do this.....
IF @USERID = "GEN1"
AddPrinterConnection("\\PRINTSERVER\HP PRINTER")
ELSEIF @USERID = "GEN2"
AddPrinterConnection("\\PRINTSERVER\HP PRINTER 2")
ELSEIF @USERID = "GEN3"
AddPrinterConnection("\\PRINTSERVER\HP PRINTER 3")
ELSEIF @USERID = "GEN 4"
AddPrinterConnection("\\PRINTSERVER\HP PRINTER 4")
ENDIF

Top
#201681 - 2011-03-02 12:27 AM Re: IF..ELSE IF...ENDIF Limitation? [Re: AshishS]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
I do not know of any limit. However you must have a ENDIF for every IF...

However in this case, it would appear that Select Case would be more appropriate.

 Code:
Select
  case @userid="Someone"
    ;do stuff
  case @userid="SomeoneElse"
    ;do stuff
;  case ...
Endselect

Top
#201682 - 2011-03-02 12:53 AM Re: IF..ELSE IF...ENDIF Limitation? [Re: Allen]
AshishS Offline
Fresh Scripter

Registered: 2008-10-27
Posts: 20
Allen,
Thanks for your feedback. Currently I'm using Case statement with a function to see if the computer belongs in a specific group and if it does, do some stuff. Would it be possible to modify my existing Case statement and include @USERID piece without breaking the script.
Below is part of my script...

Select
Case ComputerInGroup("Admin") = 0 and (@userid = "Gen1")
AddPrinterConnection("\\PRINTSERVER\HP PRINTER")
EndSelect

So can I modify my statement to this and would it still work properly?
Select
Case ComputerInGroup("Admin") = 0 and (@userid = "Gen1")
AddPrinterConnection("\\PRINTSERVER\HP PRINTER")
Case @userid = "Gen2"
AddPrinterConnection("\\PRINTSERVER\HP PRINTER2")
EndSelect

Top
#201683 - 2011-03-02 01:11 AM Re: IF..ELSE IF...ENDIF Limitation? [Re: AshishS]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Not exactly. Case is exclusive, meaning, once it finds one thing that is true, the rest of the cases are ignored. I doubt this is what you want. Case works well with @userid because everyone usually only has one. Case does not tend to work well with groups because users/computers can be in multiple groups.

You could always start a second select case grouping for @userid's, after the group select.

Top
#201684 - 2011-03-02 01:17 AM Re: IF..ELSE IF...ENDIF Limitation? [Re: Allen]
AshishS Offline
Fresh Scripter

Registered: 2008-10-27
Posts: 20
So based on what you said, does it mean that my existing case statement with ComputerInGroup & @userid is not working properly? Or are you saying that I can use Case with ComputerInGroup and @userid but not combine @userid in the next statement?

So this will work...
Select
Case ComputerInGroup("PATIENTROOM") = 0 and (@userid = "GEN1")

but not this...
Select
Case ComputerInGroup("PATIENTROOM") = 0 and (@userid = "GEN1")
do something
Case @userid
do something
EndSelect

Sorry if the questions sound kind of dumb. Just learning kix thats all.

Thanks for all your feedback as well. I really appreciate it.

Top
#201685 - 2011-03-02 01:34 AM Re: IF..ELSE IF...ENDIF Limitation? [Re: AshishS]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
All of those will work... BUT... once one of those is true, the rest of the case are completely ignored.

I would use IF's for groups and SELECTs for userids

 Code:
if ingroup("groupname")
  ;do stuff
endif

if computeringroup("groupname")
  ;do stuff
endif

select
  case @userid="xxx"
    ;do stuff
  case @userid="yyy"
    ;do stuff
; ...
endselect


You might also consider reading up on using INI files, especially for the userids. You could create a single INI file that contains all the userid and the special drive mappings or printers that they need.

The ini would look something like
[user1]
printer=\\server\printer

[user2]
printer=\\server\printer2


There are several UDFs that read in the values for you. See ReadProfileString in the manual, or the link in my signature. You can also search the board, as there has to be hundreds of examples doing this.

Top
#201686 - 2011-03-02 02:02 AM Re: IF..ELSE IF...ENDIF Limitation? [Re: Allen]
AshishS Offline
Fresh Scripter

Registered: 2008-10-27
Posts: 20
Thanks for the feedback and pointing me in the right direction Allen.
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
0 registered and 557 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.07 seconds in which 0.031 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