Page 1 of 1 1
Topic Options
#122250 - 2004-07-07 08:10 AM as fast as CASE?
jechilt Offline
Starting to like KiXtart

Registered: 2000-12-01
Posts: 102
Loc: Denver Colorado
I set up a SELECT CASE to map our network drives to hopefully replace the large If Else statements we had. Also, I read that SELECT CASE is faster than using IF Else statements. I have bumped into a problem where SELECT CASE allows only one CASE statement to be executed, regardless of how many statements evaluate to TRUE.

Is there any way to run a series of network drive connections that runs faster than using IF Else statements?

Kind Regards///
_________________________
John
LM Contractor
One of the 2 dads

Top
#122251 - 2004-07-07 10:02 AM Re: as fast as CASE?
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
You may have more than one Select/Case condition being true, but when the first one is triggered the remaining ones are skipped.

The "slowness" of IF operations will not be significant during login, so don't worry about it too much.

If you were checking the conditions in a loop which is executed many thousands of times you might be concerned about the overhead.

The major benefit of SELECT for most people is not a speed issue, but rather a maintenance and support issue. It is easier to maintain a script which is using SELECT than it is to maintain one with nested IFs.

Depending on the complexity of your setup, the simplest solution is to keep the SELECT construct for the majority of your mappings. Break out just those sections which may be coincidental into individual IF statements to follow your SELECT structure, or a second smaller SELECT if it is appropriate.

Code:

; Membership of groups A-C is mutually exclusive.
Select
Case InGroup(A)
Map A drives
Case InGroup(B)
Map B Drives
Case InGroup(C)
Map C Drives
EndSelect

; Users may appear in group Z as well as other groups.
If InGroup(Z)
Map Z drives
EndIf



If you are worried about speed don't forget to order your CASE clauses so that the most likely one is first, and the least likely last.

Top
#122252 - 2004-07-08 04:44 AM Re: as fast as CASE?
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Quote:

a problem where SELECT CASE allows only one CASE statement to be executed



This is not a problem but by design! Teh SELECT-CASE-ENDSELECT construct processes only the first CASE statement that evaluates to TRUE. This is explained in the KiXtart Manual.

One can also provide the mapping information in an external .INI file instead of using a long list of IF conditions
Example code:
Code:

;-------------------------------------
; function to map drives based on user groups
;
; Structure of the .INI file:
;[UNC]
;Drive = drive letter to which the UNC name will be mapped
;Label = optional lable for Windows 2000/XP/2003
;GroupInclude = User groups to be included in the drive share
;CompExclude = Computers to be excluded from the drive share
;UserInclude = Users to be included in the drive share
;NetworkType = Type of network connection allowed for this share (LOCAL, LAN, VPN, DIALUP)
;Persistent = True if mapping is persistent
;DenyGuestAccess = True if guests are not allowed to access this share
;-------------------------------------
function NETWORKED_DRIVES
Dim $uncs, $drive, $unc, $persistent, $rc, $server
Dim $GroupInclude, $CompExclude, $UserInclude, $denyguestaccess
Dim $networktype, $label

if not exist($SHARESINI)
$rc=warning('NETWORKED_DRIVES: Cannot open network shares initialization file '+$SHARESINI)
exit 0
endif

$rc=displaytext('Connecting network shares')

$uncs=readprofilestring($SHARESINI,'','')
$uncs=atrim(split($uncs,chr(10)))
for each $unc in $uncs
if $unc
$drive=trim(readprofilestring($SHARESINI,$unc,'Drive'))
if $drive
$denyguestaccess=val(readprofilestring($SHARESINI,$unc,'DenyGuestAccess'))
if $GUESTACCESS=1 and $denyguestaccess=1
$rc=displaytext('Guest access is not allowed to UNC '+$unc)
use $drive+':' /delete /persistent
else
$networktype=readprofilestring($SHARESINI,$unc,'NetworkType')
$networktype=atrim(split($networktype,','))
if ascan($networktype,$NETWORKCONNECTION)+1
$GroupInclude=readprofilestring($SHARESINI,$unc,'GroupInclude')
$GroupInclude=atrim(split($GroupInclude,','))
$CompExclude=readprofilestring($SHARESINI,$unc,'CompExclude')
$CompExclude=atrim(split($CompExclude,','))
$UserInclude=readprofilestring($SHARESINI,$unc,'UserInclude')
$UserInclude=atrim(split($UserInclude,','))
$persistent=val(trim(readprofilestring($SHARESINI,$unc,'Persistent')))
$label=trim(readprofilestring($SHARESINI,$unc,'Label'))
; translate macros in UNC
if instr($unc,'@@')
$rc=execute('$unc="'+$unc+'"')
endif
; translate macros in label
if instr($label,'@@')
$rc=execute('$label="'+$label+'"')
endif
if isincluded($GroupInclude, $CompExclude, $UserInclude)
$rc=mapdrive($drive,$unc,$persistent,$label)
if @ERROR
$rc=err('Unable to map to share '+$unc+' due to the following error : '+@SERROR,,$ALERTSERVER)
else
$rc=displaytext('Mapping drive '+$drive+' to share '+$unc)
endif
else
$rc=warning('Not authorized to map drive letter '+$drive+' to '+$unc)
use $drive+':' /delete /persistent
endif
else
$rc=warning('Network connection type '+$NETWORKCONNECTION+' not authorized to map drive letter '+$drive+' to '+$unc)
use $drive+':' /delete /persistent
endif
endif
endif
endif
next
endfunction

_________________________
There are two types of vessels, submarines and targets.

Top
#122253 - 2004-07-08 09:43 AM Re: as fast as CASE?
jechilt Offline
Starting to like KiXtart

Registered: 2000-12-01
Posts: 102
Loc: Denver Colorado
nice....!

I am going to keep this example for a rainy day

unfortunately, our environment has a high turnover of personnel and we have to keep the script as simple as possible. I ended up doing IF statements.

thanks for the info!!!
_________________________
John
LM Contractor
One of the 2 dads

Top
#122254 - 2004-07-09 05:32 AM Re: as fast as CASE?
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
The advantage of this solution is that drive mappings are being controlled on the group/user-level and changes are only required in the .INI if necessary without touching the actual KiXtart script. This provides more flexibility that a multitude of IF statements.
_________________________
There are two types of vessels, submarines and targets.

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 (Henriques) and 2516 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.153 seconds in which 0.126 seconds were spent on a total of 12 queries. Zlib compression enabled.

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