Skip to main content

Variables

Variables are declared in one of the variable sections. A variable can be declared with

  • an elementary data type or
  • a user-defined type or
  • a reference type or
  • a user-defined type within the variable declaration.

A variable declaration consists of

  • a list of variable names to be declared
  • a ":" (colon) and
  • a data type with optional variable-specific initialization.
Beispiel
VAR
myVar1, myVar2: INT; // two variables with an elementary type
myVar2: myType; // use a previously user-defined type
myVar3: ARRAY [1..8] OF REAL; // use an immediate user-defined type
END_VAR

Initialization of variables

The default initial value(s) of a variable is (are)

  1. the default initial value(s) of the underlying elementary data types
  2. NULLif the variable is a reference,
  3. the user-defined value(s) of the assigned data type; This value is optionally specified using the assignment operator := in the TYPE declaration,
  4. the user-defined value(s) of the variable; This value is optionally specified with the assignment operator := in the VAR declaration.

Variable types

| type | usage| | -- | | | VAR | Internal within an entity (function, function block, etc.) | | VAR_INPUT | Input variable, not changeable within entity | | VAR_OUTPUT | Output variable, not changeable within entity.) | | VAR_INPUT | Input variable, not changeable within the entity | | VAR_OUTPUT| Output variable, provided by the entity | | VAR_IN_OUT | Input-output variable, provided externally, can be modified by the entity and is released | | VAR_EXTERNAL | Provided by the configuration of VAR_GLOBAL | | VAR_GLOBAL | Global variable | | VAR_ACCESS | Variable access path for HMI and external data sources | | VAR_TEMP | Temporary variable within entities | | VAR_CONFIG | Instance-specific initialization and location assignment | | END_VAR | End of variable declaration |