#92301 - 2003-07-02 04:36 PM
Re: Object Variables and UDFs
|
Chris S.
MM club member
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
If you Dim the object variable in the function it will remain local to the function. Otherwise, you can still access the object.
Demonstration...
code:
Break On
GetUserName(@WKSTA) ?
For Each $objComputer in $colComputer $objComputer.UserName ? Next
Function GetUserName($sComputer) ;Dim $colComputer $colComputer = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $sComputer + "\root\cimv2").ExecQuery("Select * from Win32_ComputerSystem") For Each $objComputer in $colComputer $GetUserName = $objComputer.UserName Next EndFunction
|
Top
|
|
|
|
#92304 - 2003-07-02 05:10 PM
Re: Object Variables and UDFs
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
If you are using SetOption("Explicit","ON") (and you really should be) then undeclared globals will cause an error.
Other than that there is no difference. Page 22 of the manual states: quote: Implicit declaration ... Note that all variables that are declared in this way have a global scope
|
Top
|
|
|
|
#92307 - 2003-07-02 05:24 PM
Re: Object Variables and UDFs
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Interesting.
I've always done:
code:
Global $MyArray Redim $MyArray[10]
Can't remember why. Probably as a kludge between features
|
Top
|
|
|
|
#92311 - 2003-07-02 10:01 PM
Re: Object Variables and UDFs
|
Shawn
Administrator
Registered: 1999-08-13
Posts: 8611
|
SetOption what ? explicit ? Never heard of, is that one of those methods supported by $Honey ? Kinda like $Honey.AlwaysOnTop = 1
-Shawn
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
0 registered
and 515 anonymous users online.
|
|
|