Can a function return more than one value ?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a report that prints monthly percentages and then a quarterly
percentage.
I have a function that calculates the monthly percentages. I'd like this
function to pass back not only the percentage but also the dividend and
divisor for the calculation so that I can use these to form the quarterly
percentage. Is this possible or is there a more elegant solution?
Each figure in the calculation is obtained by running a complex SQL query so
I don't want to run each one more than once.
Thanks for any advice.
 
You can return an array, a collection, or a delimited string. Here's an
example using an array ...

Public Function TestFunc() As Variant

TestFunc = Array(1, "two", #3/3/2003#)

End Function

Public Sub CallTestFunc()

Dim varLoop As Variant
Dim varArray As Variant

varArray = TestFunc()
For Each varLoop In varArray
Debug.Print varLoop
Next varLoop

End Sub
 
Back
Top