E156 - Operator not defined for these operand types
The functions ADD, SUB, MUL, and DIV report this error for an argument no arithmetic is defined for, such as a string or a bit string in ADD(1, 'x'). The operators and the same functions report it for a combination of date and time operands the standard does not define. Arithmetic on date and time types is only defined for the combinations of IEC 61131-3:
| Left | Operator | Right | Result |
|---|---|---|---|
TIME | +, - | TIME | TIME |
TIME_OF_DAY | +, - | TIME | TIME_OF_DAY |
DATE_AND_TIME | +, - | TIME | DATE_AND_TIME |
DATE | - | DATE | TIME |
TIME_OF_DAY | - | TIME_OF_DAY | TIME |
DATE_AND_TIME | - | DATE_AND_TIME | TIME |
TIME | *, / | any number | TIME |
| any number | * | TIME | TIME |
The long types LTIME, LTIME_OF_DAY, LDATE, and LDATE_AND_TIME follow the same table
among themselves. The two families do not mix. A duration plus or minus a bare integer is
accepted with warning E157.
Erroneous code example:
PROGRAM mainProg
VAR
start, stop : DATE_AND_TIME;
total : DATE_AND_TIME;
END_VAR
total := start + stop;
END_PROGRAM
Two points in time do not add up. Their difference is a duration:
PROGRAM mainProg
VAR
start, stop : DATE_AND_TIME;
elapsed : TIME;
END_VAR
elapsed := stop - start;
END_PROGRAM