#133114 - 2005-01-28 03:37 PM
Is it possible to return two variable's through a function?
|
googhum
Fresh Scripter
Registered: 2004-12-20
Posts: 7
|
I have a mainscript that calls a function, and this function gets some data from a database.
Code:
"Begin"
GetSharesPrinters(@UserID)
Exit 1
This function creates two array's, one containing Sharesinfo and the other Printerinfo. But i can only return one of these arrays:
Code:
Function GetShares&Printers($Logon)
"Do sommething"
$GetShares&Printers = $Shares
EndFunction
Is it possible two return both Shares and Printers?
Problem solved, i use "Global" arrays. And "redim" them in the function.
Edited by googhum (2005-01-28 03:45 PM)
|
|
Top
|
|
|
|
#133116 - 2005-01-28 04:40 PM
Re: Is it possible to return two variable's through a function?
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Don't use globals. Globals are baaad.
Use the multi dimensional array approach as Jochen suggested. You may return an array which contains other arrays or plain variables.
Here is a simple example:
Code:
$RETURN=udfFruitColours()
$FruitList=$RETURN[0]
$ColourList=$RETURN[1]
For $i = 0 To Ubound($FruitList)
"A "+$FruitList[$i]+" is "+$ColourList[$i] ?
Next
Function udfFruitColours()
Dim $asFruit,$asColour
$asFruit="Lemon","Strawberry","Lime","Banana"
$asColour="Yellow","Red","Green","Yellow"
ReDim $udfFruitColours[2]
$udfFruitColours[0]=$asFruit
$udfFruitColours[1]=$asColour
Exit 0
EndFunction
Exit 0
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 507 anonymous users online.
|
|
|