Parameter List

Gives the parameters that a caller must supply before a procedure runs. For more than one parameter, you must put a comma between each one.


Without parentheses

mandatory_parameters [ , Optional optional_parameters ]

With parentheses

( [ mandatory_parameters [ , Optional optional_parameters ] ] )



Mandatory parameter

[ ByRef ] declarator

Optional parameter

[ ByRef ] declarator [ = default_value ]


name [ ( [ * rank ] ) ] [ As type | In unit ]
Optional modifier (short for "by reference") lets the passed argument have its value changed by the procedure. Thus the parameter becomes an alias of the argument. Without this, the parameter is a copy of the argument. But objects and arrays are always passed by reference.
Mandatory identifier that becomes a local variable to the procedure.
Optional integer literal. Specifies the number of dimensions of the passed array.
Optional data type
Optional unit of measure
Optional constant of a type compatible with type or unit.




The examples that follow use procedures of the type Method, but this makes no difference. Also, the lines End Method are not given to help show the parameter syntax.

No parameters

Method DoSomething
    ' Does not return a value.
Method GetNumber%
    ' Returns an integer.
Method GetNumber() As Int32
    ' This is almost the same as above, with more verbosity.

One or more mandatory parameters

Method Increment amount As Int32
    ' Has one mandatory parameter passed by value.
    ' Does not return a value.
Method GetPoint(ByRef x As Int32, ByRef y As Int32)
    ' Has two parameters passed by reference.
    ' Does not return a value.
    ' The parentheses are optional.
Method AddStudent(name As String) As Int32
    ' Has one parameter passed by value.
    ' Returns an integer value.
    ' String is a reference type.
    ' The parentheses are mandatory.

One or more optional parameters

Method AddStudent name As String, Optional dob As DateTime
    ' Has one mandatory and one optional parameter.
    ' Does not return, thus parentheses are optional.
    ' If dob is not supplied by the caller,
    ' it has its default value.

See also