Declaration of in-out variables in ST

Syntax
VAR_IN_OUT
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 type;
(* Additional pieces of data are also possible for the variables. *)
END_VAR

Bedeutung

Declaration of one or more →in-out variables, name_1 , name_2 etc. must be →IEC-identifiers.
The declaration of more sections of this kind is allowed. The declaration is possible within the declaration of a →function block, of a →function or of a →method.

A →data type is possible as a type for a variable.

See "Supported data types" to learn which data types are supported for the declaration of variables. Moreover, it is 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 Within a section VAR_IN_OUT...END_VAR, it is also possible to declare function block instances.

Example
VAR_IN_OUT
In_out1 : INT;
In_out2: ARRAY [1..2] of BOOL;
In_out3 : STRING[10];
END_VAR

Mind the following when you are using in-out variables:

  • →Assignments to in-out variables demand expressions on the right side of the assignment operator ":=" which might be on the left side of the assignment operator ":=" as well. Moreover, in case of a variable, it must be a non-temporary variable (compare: →temporary variable).

  • For calls of blocks with in-out variables, you have to use formal calls (see FAQ article " When to use a formal call? When to use a non-formal call?" for information when to use formal calls). Moreover, the in-out variables must always be of the same data type because a n implicit conversion for in-out variables is not allowed. It is not allowed to assign an in-out variable to itself within the call – thus, this call is not possible: MyFB(In_out1 := MyFB.In_out1);

  • The call of a function block instance is allowed, when it has been declared as in-out variable.

  • The reading access to an in-out variable is not allowed outside of the function block or the function. Likewise, an assignment to it outside the call of the function block or the function is not allowed.

  • In case of calling a function block instance it is possible to assign an →input variable to an in-out variable of the same function block instance. However, logi.cals advises you not to do so because subsequently it would be possible to modify values for input variables within the function block. This is not allowed according to the →IEC-standard.