Function with multiple parameters

Very very basic question: is it possible to pass multiple parameters to a function and have it return multiple results somehow?
In case, how should the syntax (both for the passing call and for the returned results) be?
Thank you

Passing multiple parameters is simple:

Function MyFunction (x As Integer, y As Text, z As Text) As Something

for example. You can also do something like this:

Function MyFunction (x As Integer, ParamArray someText() As Text) As Something

You can call this as x = MyFunction( 3, "A", "B", "C", "D" ) and those text values will populate the someText() array.

As for passing back multiple values, there are a few options. First, you can include ByRef parameters in the call that the method will populate, something like this:

Sub MyMethod (x As Integer, y As Text, ByRef return1 As Integer, ByRef return2 As Text )
  return1 = x
  return2 = y
End Sub

// Call this like:
dim x as integer
dim y as text
MyMethod 5, "hi", x, y

// x and y will now be populated

Or you can use a function that returns an array, Dictionary, or instance of a class you define that has properties for the various values.

for multiple return values, you can use the tuple class

[code]Class Tuple
Sub Constructor(items() as Variant)
for each item as Variant in items
self.Elements.Append item
End Sub

Function Operator_Compare(t as Tuple) As Integer
if t is nil then
return 1
if self.Count > t.Count then
return 1
elseIf self.Count < t.Count then
return -1
dim cmp as Integer = 0
for i as Integer = 0 to UBound(self.Elements)
if self.Elements(i) > t.Elements(i) then
cmp = 1
elseIf self.Elements(i) < t.Elements(i) then
cmp = -1
end if
return cmp
end if
end if
End Function

Sub Operator_Convert(p as Pair)
dim items() as Variant
if p <> nil then
items.Append p.Left
if p.Right isA Pair then
p = p.Right
items.Append p.Right
end if
end if
End Sub

Function Operator_Subscript(offset as Integer) As Variant
return self.Elements(offset)
End Function


Count As Integer

return 1 + UBound(self.Elements)
End Get

End Set

Private Elements() As Variant

Read Me
Tuple is an extension of the Pair class that holds more than two objects. A Tuple is not the same as a list object; it is intended to
represent a group of objects as a single entity.
You can use Pair syntax to create a Tuple.
dim t as Tuple = 1 : 2 : 3
It supports subscript access to its elements:
print t(1)
Tuple indices start at 0.

End Class[/code]

retrieved it : this tuple class came from here :

1 Like

Thank you everybody for your excellent suggestions