ByRef and ByVal

ByRef gives other subroutines and functions the permission to make changes to variables that are passed in as parameters. The keyword ByVal denies this permission and the parameters cannot be reassigned outside their local procedure. ByRef is the Enable default and does not need to be used explicitly. Because ByRef is the default all variables passed to other functions or subroutines can be changed, the only exception to this is if you use the ByVal keyword to protect the variable or use parentheses which indicate the variable is ByVal.

For example, if the arguments or parameters are passed with parentheses around them, you must inform Enable that they are passed with the ByVal keyword:

SubOne var1, var2, (var3)

The parameter var3 in this case is passed by value and cannot be changed by the subroutine SubOne.

Function R( X As String, ByVal n As Integer)

In this example the function R is receiving two parameters X and n. The second parameter n is passed by value and the contents cannot be changed from within the function R.

In the following code samples, scalar variable and user defined types are passed by reference.

More:

Scalar Variables

Passing User Defined Types by Ref to DLLs and Enable functions