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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning multiple values from a function

Status
Not open for further replies.

dlpastel

Programmer
Joined
Aug 8, 2002
Messages
114
Location
US
A basic question but I have never done it.

I need to return multiple values from a function. What is the correct syntax?

myvalue = myfunction()


function myfunction() as string
myfunction = "my result"
end function

I know this makes myvalue be the value of myfunction but what if I want to return 4 or more values?

Thanks,
Dan
 
In detail, this cannot be done a FUNCTION, in Ms. Speak, returns one (and only one) value / variable. In practice, that value can be a UDT, an Array or a CSV string.





MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Hi Dan:

Do you need to return the multiple values explicitly from the function (like
Code:
MyResult = MyFunction(. . .)
) or would using the ByRef calling feature be adequate?

For example:

Code:
    MyResult = MyFunction(intAnotherReturnedValue)

    . . . 

    Private Sub MyFunction(ByRef intARV as Integer) as String

        . . .

        intARV = len(strReturnString) 
        ' MyFunction will "return" intARV since it has 
        ' been declared ByRef.  Thus, intAnotherReturnValue 
        ' will be updated.


        . . .

        MyFunction = strReturnString
    End Sub

Cassie
 
What is the best way to return multiple values then?

Thanks,
Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top