Parameter List
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

Parameter List

Updated: August 2008

Specifies the parameters a procedure expects when it is called. Multiple parameters are separated by commas. The following is the syntax for one parameter.

[ <attributelist> ] [ Optional ] [{ ByVal | ByRef }] [ ParamArray ] 
parametername[( )] [ As parametertype ] [ = defaultvalue ]


Optional. List of attributes that apply to this parameter. You must enclose the Attribute List in angle brackets ("<" and ">").


Optional. Specifies that this parameter is not required when the procedure is called.


Optional. Specifies that the procedure cannot replace or reassign the variable element underlying the corresponding argument in the calling code.


Optional. Specifies that the procedure can modify the underlying variable element in the calling code the same way the calling code itself can.


Optional. Specifies that the last parameter in the parameter list is an optional array of elements of the specified data type. This lets the calling code pass an arbitrary number of arguments to the procedure.


Required. Name of the local variable representing the parameter.


Required if Option Strict is On. Data type of the local variable representing the parameter.


Required for Optional parameters. Any constant or constant expression that evaluates to the data type of the parameter. If the type is Object, or a class, interface, array, or structure, the default value can only be Nothing.

Parameters are surrounded by parentheses and separated by commas. A parameter can be declared with any data type. If you do not specify parametertype, it defaults to Object.

When the calling code calls the procedure, it passes an argument to each required parameter. For more information, see Differences Between Parameters and Arguments.

The argument the calling code passes to each parameter is a pointer to an underlying element in the calling code. If this element is nonvariable (a constant, literal, enumeration, or expression), it is impossible for any code to change it. If it is a variable element (a declared variable, field, property, array element, or structure element), the calling code can change it. For more information, see Differences Between Modifiable and Nonmodifiable Arguments.

If a variable element is passed ByRef, the procedure can change it as well. For more information, see Differences Between Passing an Argument By Value and By Reference.


  • Parentheses. If you specify a parameter list, you must enclose it in parentheses. If there are no parameters, you can still use parentheses enclosing an empty list. This improves the readability of your code by clarifying that the element is a procedure.

  • Optional Parameters. If you use the Optional modifier on a parameter, all subsequent parameters in the list must also be optional and be declared by using the Optional modifier.

    Every optional parameter declaration must supply the defaultvalue clause.

    For more information, see Optional Parameters.

  • Parameter Arrays. You must specify ByVal for a ParamArray parameter.

    You cannot use both Optional and ParamArray in the same parameter list.

    For more information, see Parameter Arrays.

  • Passing Mechanism. The default mechanism for every argument is ByVal, which means the procedure cannot change the underlying variable element. However, if the element is a reference type, the procedure can modify the contents or members of the underlying object, even though it cannot replace or reassign the object itself.

  • Parameter Names. If the parameter's data type is an array, follow parametername immediately by parentheses. For more information on parameter names, see Declared Element Names.

The following example shows a Function procedure that defines two parameters.

Public Function howMany(ByVal ch As Char, ByVal st As String) As Integer 
End Function 
Dim howManyA As Integer = howMany("a"c, "How many a's in this string?")




August 2008

Added links to topics on optional parameters and parameter arrays.

Customer feedback.

© 2015 Microsoft