Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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:

LeftOperatorRightResult
TIME+, -TIMETIME
TIME_OF_DAY+, -TIMETIME_OF_DAY
DATE_AND_TIME+, -TIMEDATE_AND_TIME
DATE-DATETIME
TIME_OF_DAY-TIME_OF_DAYTIME
DATE_AND_TIME-DATE_AND_TIMETIME
TIME*, /any numberTIME
any number*TIMETIME

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