Parameter List - Visual Basic (original) (raw)

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

Syntax

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

Parts

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

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

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

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

ParamArray
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.

parametername
Required. Name of the local variable representing the parameter.

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

defaultvalue
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.

Rules

Example

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?")

See also