CitectVBA Programming Reference > Understanding CitectVBA Language Basics > Variables

Variables

Variables are used in CitectVBA to temporarily store data values. Variables let you assign a descriptive name to the data you are working with. You can create a variable once only in your code, and reference (refer to) it thereafter as many times as you like, by using its name in your code in place of the data value. Unlike constants, the value that a variable holds can be changed during the runtime of the project.

All variables declared within a CitectVBA procedure (subroutine or function) have local scope to that procedure only. 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, retain their assigned values between references, even after that procedure moves out of scope.

CitectVBA code used within a CitectSCADA command or expression field is treated as if the command or expression is a separate CitectVBA procedure. Variables declared within such a command procedure have procedural scope and lifetime, as described above.

Variables declared using the staticstatement at the modular level (outside any procedure) in a CitectVBA file, have modular scope to all procedures within that same CitectVBA module (file). Modular level staticvariables retain their assigned values for the entire runtime of the project.

Variables declared (using the dim,global,orpublicstatements) at the modular level (outside any procedure) in a CitectVBA file do, however, have global scope within the CitectSCADA project.

Note:Global and public statements are redundant at the modular (global) level in CitectVBA, as they perform the exact same duty as the dim statement.