Used to pass a parameter by value. This is the default for parameters so this is completely optional.


ByVal parameter As DataType





Parameter to be passed by value.


Any valid data type

The data type of the parameter.


Parameters passed by value are treated as local variables inside the method-just like variables that are created using the Var statement. This means that you can modify the values of the parameters themselves rather than first assigning the parameter to a local variable. For example, if you pass a value in the parameter "x", you can increment or decrement the value of x rather then assigning the value of x to a local variable that is created using Var.

To pass a parameter by reference, you use the ByRef keyword in the parameter declaration for the method. If you precede a parameter name by the keyword ByRef, you pass information by reference. When you pass information by reference, you actually pass a pointer to the variable containing the information. The practical advantage of this technique is that the method can change the values of each parameter. When you pass parameters by value, it doesn't do this because in effect the parameter only represents a copy of the data itself.


By default, all arrays and objects are reference types that are passed ByVal. Because they are reference types, changes made to that array or object will be reflected in the calling method. This is no different than assigning an array or object to a second variable or property.


All project types on all supported operating systems.

See also

ByRef keyword.