Introduction
When an assignment is performed, the current value of a single or multi-element variable is replaced by the result of the evaluation of the expression.
An assignment consists of a variable specification on the left
side, followed by the assignment operator :=, followed
by the expression to be evaluated.
Both variables (left and right sides of the assignment operator) must have the same data type.
Arrays are a special case. After being explicitly enabled, assignment of two arrays with different lengths can be made.
Assigning the Value of a Variable to Another Variable
Assignments are used to assign the value of a variable to another variable.
The instruction
A := B ;is used, for example, to replace the value
of the variable A with the current value of variable B. If A and B are elementary
data types, the individual value of B is passed to A. If A and B are derived
data types, the values of all B elements are passed
to A.
Assigning the Value of a Literal to a Variable
Assignments are used to assign a literal to variables.
The instruction
C := 25 ;is used, for example, to assign the value 25 to the variable C.
Assigning the Value of an Operation to a Variable
Assignments are used to assign to a variable a value which is the result of an operation.
The instruction
X := (A+B-C)*D ;is used, for example, to
assign the result of the operation (A+B-C)*D to the
variable X.
Assigning the Value of an FFB to a Variable
Assignments are used to assign a value returned by a function or a function block to a variable.
The instruction
B := MOD(C,A) ;is used, for example, to
call the MOD (Modulo) function and assign the result
of the calculation to the variable B.
The instruction
A := MY_TON.Q ;is used, for
example, to assign the value of the Q output of the MY_TON function block (instance of the TON function block) to the variable A. (This is not
a function block call) )
Multiple Assignments
Multiple assignments are a supplement to IEC 61131-3 and must be enabled explicitly.
Even after being enabled, multiple assignments are NOT allowed in the following cases:
in the parameter list for a function block call
in the element list to initialize structured variables
The instruction
X := Y := Zis allowed.
The instructions
FB(in1 := 1, In2 := In3 := 2) ;and
strucVar := (comp1 := 1, comp2 := comp3 := 2) ;are not allowed.
Assignments between Arrays and WORD-/DWORD Variables
Assignments
between arrays and WORD-/DWORD variables
are only possible if a type conversion has previously been carried
out, e.g.:
%Q3.0:16 := INT_TO_AR_BOOL(%MW20) ;The following conversion functions are available (General Library,
family Array):
MOVE_BOOL_AREBOOLMOVE_WORD_ARWORDMOVE_DWORD_ARDWORDMOVE_INT_ARINTMOVE_DINT_ARDINTMOVE_REAL_ARREAL

