Embedded if statements

Using vision version 8.21

I have no control over what is in the plc but I need to do the following:

Create four maintained PB's which each have their own boolean tag value, for example: Bool1, Bool2, Bool3, and Bool4
Create one label with a script on the text field to do the following:
if Bool1 is true, text will say 'Bool1',
if Bool2 is true, text will say 'Bool2',
if Bool3 is true, text will say 'Bool3',
if Bool4 is true, text will say 'Bool4',
else have text say 'None' as failsafe if none of true

Within the plc program if one boolean goes high the others go low so there is never a situation where two booleans can be true at the same time.

I attempted to create the following but its telling me the if statement cant have four arguments...

if (Bool1, 'Bool1', if(Bool2, 'Bool2', 'None'), 'None')

Any suggestions on how to do this easily?

You want binEnum paired with case:
https://docs.inductiveautomation.com/display/DOC81/binEnum
https://docs.inductiveautomation.com/display/DOC81/case

case(
	binEnum({Bool1}, {Bool2}, {Bool3}, {Bool4}),
	1, 'Bool1',
	2, 'Bool2',
	3, 'Bool3',
	4, 'Bool4',
	"Default"
)
3 Likes

Perfect thanks! Had to throw a comma after the binEnum function too

1 Like