The scope of an object determines which portions of your code scripts can use that object.
Note: The use of Global, Public, and Privatekeywords has no effect on scope in CitectVBA.
Variables and constants declared (using the Dim
, Static
, or Const
statements) within a CitectVBA procedure (subroutine or function) have local scope to only that within the procedure. This means that procedural level variables and constants cannot be referenced (accessed and used) from anywhere outside of that procedure.
|
UNINTENDED EQUIPMENT OPERATION Do not use the Global, Public, or Private keywords in your CitectVBA procedures. Using these keywords in procedures can lead to unintended equipment operation when your program is run. Failure to follow these instructions can result in death, serious injury, or equipment damage. |
Procedural level variables declared using the Dim
statement do not retain their assigned values when dereferenced. Procedural level variables declared using the Static
statement, however, do retain their assigned values between references, even after that procedure moves out of scope.
Constants declared (using the Const
statement) and variables declared (using the Static
statement) at the modular level (outside any procedure) in a CitectVBA file have modular scope to all procedures within that same CitectVBA module (file). This means that modular constants and static variables can only be referenced from a procedure located within the same file module, and cannot be referenced from outside of that file module. This has no effect in CitectVBA, even if declared using the Global
keyword.
Modular level constants and static variables retain their assigned values for the entire runtime of the project.
Variables declared (using the Dim
, Global
, or Public
statements) at the modular level (outside any procedure) in a CitectVBA module (file), have global scope within the Citect SCADA project. This means that modular CitectVBA variables (except statics) can be referenced from both inside and outside of their file module.
Global level variables can be used directly within Citect SCADA command or expression fields.
Procedures (subroutines or functions) declared within a CitectVBA file module, like global variables, have global scope within a Citect SCADA project. They can be referenced or called from any CitectVBA module, as well as from any Citect SCADA command or expression field.
Equally important, all Citect SCADA variable tags, alarm tags, and ActiveX objects are accessible to all CitectVBA file modules (and their procedures) within that project, in the same manner as they have always been accessible to project Cicode files. For information about referencing Citect SCADA project tags using CitectVBA, see Integrating CitectVBA with Citect SCADA.
Global level variables will also retain their assigned values between subsequent references, behaving somewhat similarly to the values stored in Citect SCADA tags. In this regard, Global
and Public
statements are redundant at the modular (global) level in CitectVBA, as they perform the exact same duty as the Dim
statement.
See Also
Multithread Considerations with CitectVBA
Published June 2018