Declaration of external variables in ST

Syntax
VAR_EXTERNAL (* optional_begin *) CONSTANT (* optional_end *)
name_1, name_2, ..., name_n : data-type;
name_3, name_4, ..., name_n : STRING[length];
name_5, name_6, ..., name_n : ARRAY [x..y] OF type;
name_7, name_8, ..., name_n : ARRAY [x1..y1, x2..y2, x3..y3] OF data-type;
(* Additional pieces of data are also possible for the variables. *)
END_VAR

Meaning

declaration of one or more →external variables, name_1, name_2 etc. must be →IEC-identifiers.
The declaration of more sections of this kind is allowed. The declaration of external variables is possible within declaration of a function block, the declaration of a function or within a →method. Such external variables are used to access →global variables with the same name and of the same type. These global variables are declared within a →program (within an ST-object) or within a →resource (within a PLC-object).
The declaration of external variables is possible within declaration of a program. Such external variables are used to access global variables which were declared within a resource (within a PLC-object).

Providing the optional keyword CONSTANT prevents all external variables of this section from being overwritten during program execution (makes them →constants). The keyword CONSTANT is mandatory if the corresponding global variable has been declared CONSTANT.
See "Supported data types" to learn which data types are supported for the declaration. It is also possible to declare:

Good to know

images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/lightbulb.svg Moreover, logi.CAD 3 allows you to specify additional data for the declaration . See " Defining description, comment, JSON string or type for variables or data types " for details.

images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/lightbulb.svg If you prefer that logi.CAD 3 is creating the syntax for you: The application navigator provides the possibility to declare external variables and to have the declarations based on the already existing global variables. This is done when you drag the global variables from a global-object onto a →POU. Details: See "Declaring external variables by dragging and dropping global variables into POUs". In this case, you do not need to know the syntax described above.

Example 1
VAR_EXTERNAL
portSetting : INT;
upTime : TIME;
gVar1: ARRAY [1..2] of BOOL;
gVar2: STRING[10];
END_VAR

Example 2
VAR_EXTERNAL
VALVE_POS : INT;
END_VAR