Variable Declaration

Help Contents


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:

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.

Storage Modifiers

You can use storage modifiers after the variable declaration keyword:

Storage ModifierUsed WithDescription
CONSTANTVARDeclares a constant variable locally in a Program Unit.
CONSTANTVAR_GLOBALDeclares a constant variable globally in a file.
CONSTANTVAR_EXTERNALDeclares a constant reference to a global variable. The global variable may or may not be constant.

Access Modifiers

You can use access modifiers after the variable declaration keyword:

Access ModifierDescription
PUBLICCode outside of the Class Declaration can access the variable.
PRIVATEOnly code in the Class Declaration can access the variable.
PROTECTEDReserved for future use.
INTERNALReserved for future use.

Variable Declaration Syntax

Inside a variable declaration block, you declare variables using this syntax:

variable-name [, variable-name ] : variable-type [ := initial-value ];

variable-name ::= name [ AT location ]


Directly Located Variables

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.


  1. Declaration of global variables:
        X, Y, Z : LReal; (* Coordinates *)
  2. Declaration of global constant value:
    Var_Global Constant
        MaxTags : Int := 12;
  3. Input variable to a program unit:
        V1, V2 : Vector;

    This example assumes Vector is a previously declared derived data type, for example:

        Vector : Struct X, Y : REAL; End_Struct;
  4. Temporary array:
        Buffer : Array[0..5] Of Int;
  5. Directly located variable:
        Pressure AT %".TankPressure" : LREAL

Further Information

Elementary Data Type

For the elementary types you can use for variable-type.

Derived Data Type

For the derived types you can use for variable-type.


For the meaning of terms used in Fernhill SCADA.