Expression language switch() upgrade

Hey Guys,

I think I have a workaround. If you use binEnum() in addition to the switch, you could get the result you want. If you look it up, binEnum does:[quote]This function, whose name stands for “binary enumeration”, takes a list of booleans, and returns the index of the first parameter that evaluates to true. For example:
binEnum(false,true,false)
…returns 2 ( the index of the true parameter)[/quote]If you use them together, you could get the index of the first true statement, and then index that (with the switch) to some other value. I don’t have FactoryPMI installed right now to test it, but I believe you can use expressions in binEnum.switch( binEnum({value}>5 && {value}<10, {value}!=3, {value}> 0) 1,2,3, 'one', //result 1 'two', //result 2 'three', //result 3 'none') //default While I’m thinking about it, could we do a different form of the binEnum() that is more like the switch statement? It could take in an even number of args and instead of enumerating, return the “result” that matches the first true value.

Other than that, you could just use nested if statements. It’s not pretty, but it’ll work.

if({value}>5 && {value}<10, //case 1 "one", //result 1 if({value}!=3, //case 2 "two", //result 2 if({value}>0, //case 3 "three", //result 3 "none" //default ) ) )

1 Like