Function

  • Thread starter Thread starter Ruben Granados
  • Start date Start date
Simplest way is to pass in an extra variable for the function to set.

This example shows how a function could return the sum of two arguments and
also the difference between the two arguments, by passing in a 3rd argument:


Function ShowResult (A as integer, B as integer, MySum As Integer) As
Integer
MySum = A + B
ShowResult = A - B
End Function

Sub GetResults
Dim iSum as Integer
Dim iDiff as Integer

iDiff = ShowResult(7, 5, iSum)

MsgBox "Sum is " & iSum
MsgBox "Difference is " & iDiff
End Sub


Another alternative is to create a user-defined type and have the function
return that. You can think of the type as something like a record, with
different values within the type being like the fields of the record.
Details on this approach in article:
Multiple return values from a Function
at:
http://allenbrowne.com/ser-16.html
 
Back
Top