Page 2 of 2 <12
Topic Options
#126922 - 2004-09-24 12:08 PM Re: Making the script more verbose
Testprs Offline
Fresh Scripter

Registered: 2004-09-02
Posts: 20
Loc: Netherlands, Delft
Ok, to test my insight I'll note what I think the script does, please correct me:

$sPrinter=GetDefaultPrinter() => declares $sPrinter as the value of GetDefaultPrinter
If $sPrinter
"Default printer for this user is "+$sPrinter+@CRLF => If there is a value for this variable it prints the message
Else
"No default printer found for this user."+@CRLF
EndIf => If there's no value for the variable it prints an error

; GetDefaultPrinter() - Returns the default printer.
; Sets @ERROR=0 when a printer is found, 2 if no printer is found.

Function GetDefaultPrinter() => declares function and between () the result is stated
Dim $iIndex,$sGroup => locally declares the variables $iIndex and $sGroup (is this the same as:
Dim $iIndex
Dim $sGroup
?)


$sGroup=EnumGroup($iIndex) => $sGroup is the return value of EnumGroup with value $iIndex
While @ERROR=0 AND $sGroup => as long as there is an value for $sGroup and no error continue
If InStr($sGroup,"\") $sGroup=SubStr($sGroup,InStr($sGroup,"\")+1) EndIf => If there is a \ in $sGroup $sGroup=value from \
If InStr($sGroup,"P-")=1 => if there is a P- in $sGroup
$GetDefaultPrinter=SubStr($sGroup,3) => $GetDefaultPrinter= value of $sGroup (does the 3 mean that it only shows the last 3 characters of the value?)
Exit 0 => exit on error 0
EndIf
$iIndex=$iIndex+1 => add 1 to $iIndex so the EnumGroup checks the next group during the loop
$sGroup=EnumGroup($iIndex) => $sGroup = the value of the number of the loop it is working
Loop
Exit 2 => exit on error 2
EndFunction


After reading the manual more carefully I noticed I misunderstood the EnumGroup function. A big case of RTFM .

Why there is a While...Loop construct
So every Group is stated

Why your use of @USERID was inappropriate
because an integer value is required for this function

What the $iIndex variable is being used for
so that all groups are returned

Why the line with the "\" substring is there
I'm not really sure, but I think to make sure it gets the group and not the domain

What the $GetDefaultPrinter variable is, and why it is set as it is.
declares function and between () the result is stated

What the "Exit" statements are being used for, and why they have numeric values
So that the loop quits when it has found it's value, when there is an error or if it has had all value's


What the line "While @ERROR=0 AND $sGroup" is doing.
As long as there is an value for $sGroup and no error continue

regards,

jeroen

ps.. hope this takes me of of the candidate list for the kixtart paralympics

Top
#126923 - 2004-09-24 12:58 PM Re: Making the script more verbose
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Ok, that's good, you've got almost everything.

Let's clear up the remaining bits:
Quote:

Dim $iIndex,$sGroup => locally declares the variables $iIndex and $sGroup (is this the same as:
Dim $iIndex
Dim $sGroup




Yes, it does the same thing.

Quote:

$GetDefaultPrinter=SubStr($sGroup,3) => $GetDefaultPrinter= value of $sGroup (does the 3 mean that it only shows the last 3 characters of the value?)




No. The second parameter for substring is the start position. The third parameter is the length and is optional - when not specified it means "to the end of the string.

This bit of code cuts the string from position 3 onwards, i.e. it cuts off the "P-" prefix.

Quote:

Why your use of @USERID was inappropriate
because an integer value is required for this function




Yup. EnumGroup() returns the groups for the current user. You must ask for each entry one at a time using the index (which starts at zero) - it will not return "all" groups in one call.

Quote:

Why the line with the "\" substring is there
I'm not really sure, but I think to make sure it gets the group and not the domain




Exactly right. EnumGroup() returns domain and local groups. To simplify things, I strip the domain part off so that only the group name is left.

Just to clarify the function definition.

The values between the parentheses "()" are values which are passed to the function. These cannot be changed and are not passed back to the calling script.

You may only pass back two things from the function. You may pass back an error value by using "Exit n" where n is an integer. This will set the @ERROR macro.

You may pass back a single value by setting a variable which has the same name as the function. Take the following example:
Code:

Dim $iVar1, $iVar2
$iVar1="10"
$iVar2=Increment($iVar1)

Function Increment($iVar1)
$iVar1=$iVar1+1
$Increment=$iVar1
Exit 0
EndFunction



This when called this function will always set @ERROR to zero.

The function simply takes the value passed (10), adds one to it and because is it assigned to a variable with the same name as the function it gets returned to the main script.

This means that $iVar2 is now set to 11. But what about $iVar1?

$iVar1 is still 10. This is because when you call a function the values are copied to a new variable. the variable may have the same name, but it is not the same variable as the one in the main script. The version of $iVar1 in the main script is hidden and not accessible in the function.

I hope that has cleared some things up for you.

Top
#126924 - 2004-09-24 02:36 PM Re: Making the script more verbose
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Wow Richard.
Impressive tutelage there. I hope jeroen gives you a 5 star rating there!
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#126925 - 2004-09-24 03:37 PM Re: Making the script more verbose
Testprs Offline
Fresh Scripter

Registered: 2004-09-02
Posts: 20
Loc: Netherlands, Delft
Thank you very much!
You've been a great help!
I am enjoying my login script every time I see it now!

regards,

jeroen

ps.. it's definitly a 5 start rating!

Top
Page 2 of 2 <12


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

Who's Online
0 registered and 2167 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.126 seconds in which 0.1 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