I have an expression if({PLCTAG/M24_MF}, "ON", "OFF") and instead of ON and OFF it returns me 1 and 0 respectively. I tried ONN and OFFF in expression
if({PLCTAG/M24_MF}, "ONN", "OFFF") and it works as intended returning me ONN or OFFF. Only ON and OFF does not work other all string works.
Welcome to the forum.
Please see Wiki - how to post code on this forum.
I am unable to reproduce the problem on 8.1.41.
I have an expression tag bound to myBool
(a boolean tag).
if({[default]myBool}, "ON", "OFF")
It works as expected.
What is the data type of M24_MF
?
It's a boolean.
Where's the expression/what's the output data type?
I think there's some (misguided, legacy, has to be kept for backwards compatibility) coercion code for certain strings like on/off, yes/no to boolean values in the expression language. You need to share more about where you're authoring this expression to know where the problem lies.
Would it fix it to specify Unicode to force string type?
if({[default]myBool}, u'ON', u'OFF')
[Edit: The answer is no. You'll get Error_Configuration("RuntimeException: Syntax Error on Token: 'String CONST' (Line ..., Char ...)
)
]
Can you do that in expressions ?
Apparently not - now that I've tried it.