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 :
Function TestPassArg(
Byval
intVal As Integer,
varVal, strVal as String)
TestPassArg var1, var2,
(
var3
)
TestFunction
(
(iVar)
)
Note:CitectSCADA does not support passing by reference, so CitectSCADA tag values MUST be declared by value when passed as arguments to a CitectVBA procedure from within a CitectSCADA command or expression field. This is best done by declaring the variable, assigning it the tag value, then passing the variable by value. (See the Example below.)
Example
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
:
CiVBA
Dim iVar1 as Integer
iVar1 = iTag1
TagArgumentTest(iVar1)
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