Using Parameter Arrays

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

You can pass an array of arguments to a procedure by using a parameter array. The advantage to using a parameter array is that you don't need to know at design time how many arguments will be passed to a procedure—you can pass a variable number of arguments when you call it.

To define a parameter array, use the ParamArray keyword followed by an array of type Variant, as shown in the following procedure definition:

Function SomeProc(ParamArray avarItems() As Variant)

A parameter array must always be an array of type Variant, and it must always be the last argument in the argument list.

To call a procedure that includes a parameter array, pass in a set of any number of arguments, as shown here:

? SomeProc("red", "yellow", "blue", "green", "orange")

Within the body of the procedure, you can work with the parameter array as you would with any other array.

For an example of a procedure that takes a parameter array, see the Median procedure in "Performing Calculations on Numeric Arrays" earlier in this chapter.