SA0168: Unnecessary Assignments
Detects assignments to variables which do not have any effect in the code.
Justification: When values are assigned to a variable multiple times without the variable being evaluated between assignments, the first assignments do not have any effect on the program.
Importance: Low
Example 126. Example
PROGRAM PLC_PRG
VAR
dwVal1 : DWORD;
dwVal2 : DWORD;
END_VAR
// unnecessary assignment
dwVal1 := 1;
IF dwVal2 > 100 THEN
dwVal2 := 0;
dwVal2 := dwVal2 + 1;
END_IF
dwVal1 := 2;Output in the Messages view:
SA0168: The variable 'dwVal1' is assigned, but its value is never used.