Unsupported types for BAnd: 'null' and 'java.lang.Long'

I have a button visible binding code as:
!((({Root Container.type} = 4) || ({Root Container.type} = 5)) && ({Root Container.bp.command} & 0x0080)) && !(!(({Root Container.type} = 4) || ({Root Container.type} = 5)) && ({Root Container.bp.command} & 0x0040))
The code works correctly but when I open the popup window in designer I get an error message. If I set the single & to && then the error goes away but my logic fails.

What am I doing incorrectly? Any suggetions?
FYI To shorten the code I would like to use ({Root Container.type} = (4 or 5)) but I cannot get that logic to work either.

I did find this in another post. Can I use 'try()' in a binding?
Or is this something I can just ignore as it only shows up in Designer?

You can use try().

The issue is indeed that {Root Container.bp.command} is null.

& and && have different meanings. & is a bitwise AND operator. && is a logical AND operator.

Unfortunately, the expression language does have a tendency to become very hard to read if care is not taken. There is also a lot of times where the use of a different expression will simplify the expression as well. On top of that, white space is not a factor so you can space out the expression to make it easier to read and follow.

try(

    !((({Root Container.type} = 4 || ({Root Container.type = 5)) && ({Root Container.bp.command} & 0x0080))
    &&
    !(!(({Root Container.type} = 4) || ({Root Container.type} = 5)) && ({Root Container.bp.command} & 0x0040))

,0)

What is the goal of the expression? There may be a better way to write it depending on what you are trying to accomplish.

1 Like

You could also chain transform in order not to repeat some parts of your expression.

I have the same popup window for 7 types of motor equipment. I am passing a parameter named type to determine what graphics to display in the popup window. If the (type is 4 or 5) and the command is not 0x0040 or the type is not (4 or 5) and the command is 0x0080 then show this graphic.

So this ?
((a or b) and not c) or (not(a or b) and d)

Could this be simplified with an if ?
if (a or b, not c, d)

my 1.5 months old daughter has been crying for 2 weeks straight so I might be too tired for this kind of logic, but...

Note that & is NOT =. If you're comparing for equality, use =.

Yeah, I'm thinking something like:

if({Root Container.type} = 4 || {Root Container.type} = 5
    , !({Root Container.bp.command} = 0x0040) // Type is either 4 or 5
    , {Root Container.bp.command} = 0x0080 //Type is not 4 or 5
)

I am going to show my ignorance here but I have never seen ‘,’ after an if statement
I assume that the system reads it as (true/false statement, true comparison, false comparison)

Oh is this in the transform that pascal fragnoud mentioned?

No, it’s an expression function.

if(conditional statement, true return, false return)

https://docs.inductiveautomation.com/display/DOC81/if

If the conditional statement is true the return the true return value, if it is false then return the false return value.

Thank you so much, that is fantastic!

This is the code that works for me. I might have given you slightly wrong info but wanted to say thanks for helping me solve my difficulty!

! if ({Root Container.type} = 4 || {Root Container.type} = 5, {Root Container.bp.command} & 0x0080, {Root Container.bp.command} & 0x0040)

The graphic is not visible when ((type = 4 or 5) and (command & 0x0080)) or (not (type = 4 or 5) and (command & 0x0040))