Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array function return

Status
Not open for further replies.

gymbeef

Technical User
Sep 18, 2002
33
US
Functions typically return single values, for example:

Private Function iGetResult(iInput as Integer) As Integer
...
...

will take an integer, do something, then return an integer back to whatever called it.

Instead of returning a single value, is it possible to define a function such that it will return an array of values? To illustrate what I mean:

Private Function iGetResult(strWord as String) As ???

to take a string such as strWord="cat", and then
return an array of letters:
iGetResult(0)="c"
iGetResult(1)="a"
iGetResult(2)="t"

Array variable are typically defined with parathesis, but functions use the parenthesis to define fucntion inputs, so I'm not sure if its doable, or what the syntax would be if it was.

Is there a way to do the above at all using a single function? I suppose could just store the array data in a global public variable to read outside the function, but I was wondering if there's a more elegant way to do it.

Thanks in advance.

 
Private Function iGetResult(strWord as String) As String()
Dim aryW() As String
Redim aryW(whatever)
aryW(0) = "c"
' Do Not use iGetResult(0)="c" because you will be trying
' to call yourself recursively,
iGettResult = aryW
End Function



Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top