Page 1 of 1 1
Topic Options
#133114 - 2005-01-28 03:37 PM Is it possible to return two variable's through a function?
googhum Offline
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
#133115 - 2005-01-28 03:46 PM Re: Is it possible to return two variable's through a function?
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
you may also return this as a 2-dimensional array, but returning 2 independant variables is to my best knowledge impossible
_________________________



Top
#133116 - 2005-01-28 04:40 PM Re: Is it possible to return two variable's through a function?
Richard H. Administrator Offline
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
#133117 - 2005-01-30 03:02 PM Re: Is it possible to return two variable's through a function?
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Shares and printers should be gathered via two distinct UDFs, IMHO. Otherwise, the return should be an array of arrays, not a two-dimensional array.
_________________________
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
0 registered and 507 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.054 seconds in which 0.027 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