Hello!

I stumbled into a priority problem with the boolean operators AND and OR. I cannot find any documentation for this.

First mathematical examples.

With
MsgBox( 3 * 2 ^ 2 )
you will see, that ^ has a higher priority than *.
(2 ^ 2) = 4
4 * 3 = 12
With
MsgBox( (3 * 2) ^ 2 )
you will get the right result 6 ^ 2 = 36.

With
MsgBox( 3 + 4 * 3 )
you will see, that * has a higher priority than +.
(4 * 3) = 12
3 * 12 = 36
With
MsgBox( (3 + 4) * 3 )
you will get the right result 7 * 3 = 21.

Now looking at the same logic with logical operators.

Dim bResult As Boolean
bResult = TRUE Or FALSE And TRUE
MsgBox( bResult )
bResult = TRUE Or TRUE And FALSE
MsgBox( bResult )

What do you expect?
For logical operations AND is equivalent to * and OR is equivalent to +.
AND should have a higher priority than OR, so I would expect in both cases (because TRUE Or (<anything>) = TRUE):
bResult = TRUE
But you will get
TRUE Or FALSE And TRUE = (TRUE Or FALSE) And TRUE = TRUE
TRUE Or TRUE And FALSE = (TRUE Or TRUE) And FALSE = FALSE

Is there any explanation that AND and OR have (and should have) the same priority?

Regards, Mathias

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@openoffice.apache.org
For additional commands, e-mail: dev-h...@openoffice.apache.org

Reply via email to