|
|
Title | Use the ParamArray keyword to make a routine that takes a variable number of arguments |
Keywords | ParamArray |
Categories | Software Engineering, Tips and Tricks |
|
|
Use the ParamArray keyword. The parameter should be an array of Variants. Use LBound and UBound to see how many arguments are in the parameter array.
This example uses ParamArray to make an Average function that returns the average of any number of values.
|
|
Private Function Average(ParamArray arguments() As Variant) _
As Single
Dim i As Integer
Dim total As Single
For i = LBound(arguments) To UBound(arguments)
total = total + arguments(i)
Next i
Average = total / (UBound(arguments) - _
LBound(arguments) + 1)
End Function
|
|
|
|
|
|