Variable Declaration


You can declare variables locally in a Program Unit or globally in a file. Variables declared locally in a program unit can only be accessed by that Program Unit. Variables declared globally in a file can be accessed by any Program Unit in the file.

All variable declarations begin with a keyword, which defines the start of a variable declaration block and the storage of the variables in the block:

VARDeclare local variables in a Program Unit.
VAR_INPUTDeclare input variables to a Program Unit.
VAR_OUTPUTDeclare output variables to a Program Unit.
VAR_IN_OUTDeclare variable passed by reference to a Program Unit.
VAR_TEMPDeclare a temporary variable in a Program Unit.
VAR_GLOBALDeclare a global variable.
VAR_EXTERNALDeclare 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.

Variable Declaration Syntax

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

varname [, varname ] : vartype [ := initial-value ];



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;

Further Information

Elementary Data Type

For the elementary types you can use for vartype.

Derived Data Type

For the derived types you can use for vartype.


For definitions of the terms used in Fernhill SCADA.