E037: Invalid assignment
This error is reported for assignments or accesses that are not allowed, for example when the
types of the left- and right-hand side are incompatible, when a VOID function result is
assigned to a variable, or when a variable is written or read from a place where it must not be
accessed.
Example - incompatible types
FUNCTION main
VAR
x : INT;
s : STRING;
END_VAR
x := s; (* cannot assign 'STRING' to 'INT' *)
END_FUNCTION
Example - VAR_OUTPUT assigned outside of its scope
VAR_OUTPUT variables of a function block may only be written by the function block itself.
From the outside they can only be read.
FUNCTION_BLOCK FB
VAR_OUTPUT
out : BOOL;
END_VAR
END_FUNCTION_BLOCK
PROGRAM main
VAR
fb : FB;
END_VAR
fb.out := TRUE; (* VAR_OUTPUT variables cannot be assigned outside of their scope *)
END_PROGRAM
Example - VAR_IN_OUT accessed outside of its scope
VAR_IN_OUT variables of a function block or program may not be read or written from outside.
They are references that are only bound to a target while the function block is being called, so
any outside access - reading, writing or taking the address - would dereference an unbound
reference. Pass the variable in the call instead.
FUNCTION_BLOCK FB
VAR_IN_OUT
inOut : LREAL;
END_VAR
END_FUNCTION_BLOCK
PROGRAM main
VAR
fb : FB;
value : LREAL;
END_VAR
fb.inOut := value; (* VAR_IN_OUT variables cannot be accessed outside of their scope *)
value := fb.inOut; (* VAR_IN_OUT variables cannot be accessed outside of their scope *)
fb(inOut := value); (* correct: the variable is passed in the call *)
END_PROGRAM