What Is Use Of Keyword ParamArray In Visual Basic?

1

1 Answers

raaga Profile
raaga answered
Sometimes we need a procedure that can accepts a variable number of arguments at various times during program( it means the procedure is sometimes called by passing one argument and at some later time same procedure can be called by passing two arguments etc.).

In this case we use the keyword ParamArray in definition header of the procedure that requires the variable number of arguments at various times.
We put this keyword in the parameter list that indicates that this procedure will receive a variable number of arguments.

The keyword ParamArray is preceded by the declaration of Variant array in the parameter list of that procedure.
Variant type array is used to enable the user to pass the arguments of any type.
The syntax of using this keyword ParamArray in procedure definition is given as:
Private sub myfun ( ParamArray x () as variant)
Dim y as integer

For y=LBound(x) to UBound(x)
Print x(y)
Next
End sub
Where 'myfun' is a procedure that uses ParamArray .this procedure can be called by passing various numbers of arguments as:
Call myfun (1)
Call myfun (1, 2)
Call myfun (1, 2, 3)
We can also pass the different number of arguments as well as the different types of arguments like:
Call myfun (1, "fun", 5.67)
The above call passes the three different types of arguments .

Answer Question

Anonymous