A variable is a named unit of data that is assigned a value.
You can declare variables:
All variable declarations begin with a keyword, which defines the storage of the variables in the block:
Keyword | Usage |
---|---|
VAR |
Declare local variables in:
|
VAR_INPUT |
Declare input parameters to:
|
VAR_OUTPUT |
Declare output parameters from:
|
VAR_IN_OUT |
Declare parameters passed by reference to:
|
VAR_TEMP |
Declare a temporary variable in:
|
VAR_GLOBAL | Declare a global variable. |
VAR_EXTERNAL | Declare a reference to a global variable declared in another file. |
You use the END_VAR keyword to indicate the end of a variable block.
You can use storage modifiers after the variable declaration keyword:
Storage Modifier | Used With | Description |
---|---|---|
CONSTANT | VAR | Declares a constant variable locally in a Program Unit. |
CONSTANT | VAR_GLOBAL | Declares a constant variable globally in a file. |
CONSTANT | VAR_EXTERNAL | Declares a constant reference to a global variable. The global variable may or may not be constant. |
You can use access modifiers after the variable declaration keyword:
Access Modifier | Description |
---|---|
PUBLIC | Code outside of the Class Declaration can access the variable. |
PRIVATE | Only code in the Class Declaration can access the variable. |
PROTECTED | Reserved for future use. |
INTERNAL | Reserved for future use. |
Inside a variable declaration block, you declare variables using this syntax:
variable-name [, variable-name ] : variable-type [ := initial-value ]; variable-name ::= name [ AT location ]
Where:
A directly located variable uses the AT location syntax to associate a variable name with a Tag Reference. For best results use a variable-type that is compatible with the type of the Tag Reference.
Var_Global X, Y, Z : LReal; (* Coordinates *) End_Var
Var_Global Constant MaxTags : Int := 12; End_Var
Var_Input V1, V2 : Vector; End_Var
This example assumes Vector is a previously declared derived data type, for example:
Type Vector : Struct X, Y : REAL; End_Struct; End_Type
Var_Temp Buffer : Array[0..5] Of Int; End_Var
Var Pressure AT %".TankPressure" : LREAL End_Var
For the elementary types you can use for variable-type.
For the derived types you can use for variable-type.
For the meaning of terms used in Fernhill SCADA.