Skip to content

Latest commit

 

History

History
34 lines (19 loc) · 1.1 KB

42438a68-37a8-85d0-6404-1df4266fe33d.md

File metadata and controls

34 lines (19 loc) · 1.1 KB

Understanding Parameter Arrays

A parameterarray can be used to pass an array of arguments to a procedure. You don't have to know the number of elements in the array when you define the procedure.

You use the ParamArray keyword to denote a parameter array. The array must be declared as an array of type Variant, and it must be the last argument in the procedure definition.

The following example shows how you might define a procedure with a parameter array.

Sub AnyNumberArgs(strName As String, ParamArray intScores() As Variant) 
 Dim intI As Integer 
 
 Debug.Print strName; " Scores" 
 ' Use UBound function to determine upper limit of array. 
 For intI = 0 To UBound(intScores()) 
 Debug.Print " "; intScores(intI) 
 Next intI 
End Sub

The following examples show how you can call this procedure.

AnyNumberArgs "Jamie", 10, 26, 32, 15, 22, 24, 16 
 
AnyNumberArgs "Kelly", "High", "Low", "Average", "High"