ParamArray
From Xojo Documentation
Used in a Sub or Function statement to indicate that an arbitrary number of parameters of the specified data type can be passed.
Usage
ParamArray [parameterName As DataType]
Part | Description |
---|---|
parameterName | Name of parameter for which an indefinite number of arguments will be passed. |
DataType | Data type of the parameter. It can be any valid data type. |
Notes
The ParamArray keyword enables you to pass an indefinite number of values of a specific data type without formally using an array. A call to a method or function that has been declared using ParamArray uses a comma-delimited list of values rather than an array. The ParamArray parameter is treated as an array in the method code.
ParamArray can only be used with the last parameter in a method.
Sample Code
The following function adds a list of numbers that are passed via ParamArray.
Var i, total As Integer
For Each i In nums
total = total + i
Next
Return Total
End Function
This function can now be called like this:
Any number of integers can be passed to AddNumbers.
This approach is equivalent to the use of a manually populated array. Consider the following function:
Var i, total As Integer
For Each i In nums
total = total + i
Next
Return total
End Function
You can initialize the array and call the function in the following way:
Var n As Integer
myArray = Array(5, 10, 20) // create 3 elements and assign values
n = AddArray(myArray)