How to: Call a Procedure that Takes an Indefinite Number of Parameters (Visual Basic)
A procedure can declare the last entry in its parameter list to be a parameter array. This allows it to accept an indefinite number of values for that parameter, instead of just a single value.
For more information, see Parameter Arrays (Visual Basic).
To call a procedure with a parameter array and omit the corresponding argument
Write the procedure call in the normal way. The parameter array must be the last argument.
Terminate the argument list with the next-to-last argument. The parameter array is optional, and all the preceding parameters must be required.
-or-
Supply the Nothing keyword as the argument for the parameter array.
Visual Basic passes an empty one-dimensional array to the procedure for the parameter array.
To call a procedure with a parameter array and supply a list of arguments
Write the procedure call in the normal way. The parameter array must be the last argument.
Supply any number of arguments, separated by commas, for the parameter array. The data type of each argument must be implicitly convertible to the ParamArray element type.
Visual Basic passes a one-dimensional array to the procedure, containing all the values you supplied.
To call a procedure with a parameter array and supply an array of arguments
Write the procedure call in the normal way. The parameter array must be the last argument.
For the parameter array, supply a one-dimensional array with the same element type as the parameter array's element type.
Visual Basic passes your array to the procedure.
Example
The following examples show typical calls to the studentScores procedure defined in How to: Define a Procedure with an Indefinite Number of Parameters (Visual Basic).
Call studentScores("George")
...
Call studentScores("Anne", "10", "26", "32", "15", "22", "24", "16")
Call studentScores("Mary", "High", "Low", "Average", "High")
Dim JohnScores() As String = {"35", "Absent", "21", "30"}
Call studentScores("John", JohnScores)
The first call omits the parameter array altogether and supplies only the required first argument. The studentScores procedure treats this call as passing an empty array.
The second and third calls supply argument lists of different lengths to the parameter array. Each such list is passed as an array of values.
The fourth call passes an array to the parameter array.
See Also
Reference
Concepts
Procedure Parameters and Arguments (Visual Basic)
Passing Arguments by Value and by Reference (Visual Basic)
Passing Arguments by Position and by Name (Visual Basic)
Optional Parameters (Visual Basic)