CitectVBA Programming Reference > Understanding CitectVBA Language Basics > DLLs and APIs > Passing variables Byref and Byval
Passing variables Byref and Byval

Passing an argument by reference (using the Byref parameter) passes a pointer to the memory location of that argument. A pointer is just a memory address that indicates where the value is stored. If the procedure modifies that argument's value, it modifies the source of that argument, so when execution returns to the calling procedure, the source contains the modified value.

Passing an argument to a function by value (using the Byval parameter), on the other hand, passes a copy of the value as the argument. This prevents that function from modifying the source of the argument. When execution returns to the calling procedure, the source contains the same value it did before the function was called.

The Byref parameter is the default in CitectVBA and does not need to be used explicitly within CitectVBA. Byref gives other subroutines and functions permission to make changes to the source of the values that are passed in Byref. The keyword Byval denies this permission so the argument source cannot be altered.

There are two possible methods for indicating to CitectVBA that you wish to pass an argument by value :


Suppose you had a variable tag of integer type named "iTag1" and you need to pass it to a function. From within a CitectVBA script, or CitectSCADA command or expression field, you would use the following code example to pass the variable tag value to a function named TagArgumentTest:

Dim iVar1 as Integer
iVar1 = iTag1

Note: Cicode does not support passing by reference, so CitectVBA variables passed to Cicode functions using the CicodeCallOpen function must be enclosed in brackets to force the passing of those variables by value.

See Also

Passing Arguments to DLL Functions from CitectVBA

DLLs and APIs