1. Gregory Rusak
  2. PowerBuilder
  3. Friday, 21 May 2021 16:12 PM UTC

Hello,

We're experiencing an odd issue with computed expressions, specifically the following.

Why does this expression equate to 1:

IF(NOT (1=1) AND (1 = 2), 1, 0)

While this expression correctly equates to 0:

IF( (1 = 2) AND NOT (1=1), 1, 0)

If anyone can shed some light, that would be greatly appreciated.

PowerBuilder 2019 R2 Build 2328

I've attached an exported datawindow that demonstrates this odd behaviour.

Regards,

Greg

Attachments (1)
Olan Knight Accepted Answer Pending Moderation
  1. Thursday, 24 June 2021 14:40 PM UTC
  2. PowerBuilder
  3. # 1

Gregory -
   As per Kai and John and Mike, fully parenthesizing your equation will resolve your issue.
   If this tests out to be correct, can you please mark this thread as RESOLVED?

Thanks,
Olan

Comment
There are no comments made yet.
Kai Zhao @Appeon Accepted Answer Pending Moderation
  1. Thursday, 24 June 2021 07:42 AM UTC
  2. PowerBuilder
  3. # 2

Hi Greg,

The root cause of the issue is the precedence of the operator 'not' is lower than operator 'and' in DataWindow expressions, it is different from that in PowerBuilder expressions. Please refer to online help for more details.
https://docs.appeon.com/pb2019r3/datawindow_reference/ch01s03.html
https://docs.appeon.com/pb2019r3/powerscript_reference/ch01s04s02.html

To override the order, please enclose expressions in parentheses, for your case, please change script
from
IF(NOT (1=1) AND (1 = 2), 1, 0)
to
IF((NOT 1=1) AND (1 = 2), 1, 0)

Regards,
ZhaoKai

Comment
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Friday, 21 May 2021 18:05 PM UTC
  2. PowerBuilder
  3. # 3

Hello Greg -

It appears that in the first expression, NOT is being applied to entire remainder of the expression:

IF(NOT (1=1) AND (1=2), 1, 0) 

is being evaluated as:

IF(NOT ((1=1) AND (1=2)), 1, 0)

Therefore, it looks like AND has higher operator precedence than NOT, which is not (no pun intended) what the PB Help topic "operator precedence" states.

Looks like an expression parsing/evaluation bug to me.

John

Comment
There are no comments made yet.
mike S Accepted Answer Pending Moderation
  1. Friday, 21 May 2021 18:01 PM UTC
  2. PowerBuilder
  3. # 4

always use () in datawindow expressions to avoid any of these issues

this should work:

IF( (NOT (1=1)) AND (1 = 2), 1, 0)

 

 

Comment
  1. Gregory Rusak
  2. Friday, 21 May 2021 20:57 PM UTC
Thx, although that should work (and it does), there's definitely an issue with the order in which PB evaluates the expression.
  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Friday, 21 May 2021 16:30 PM UTC
  2. PowerBuilder
  3. # 5

Hi Greg;

  FWIW: I tried this in PB 2019R3 build 2703 and the outcome is still the same. I played around with some bracketing but the outcome again is the same weird values.

  Please open a Support Ticket for this issue and attach your Test DWO to the ticket for Appeon to look into this discrepancy further.
Regards ... Chris

Comment
  1. Berka Frenfert
  2. Thursday, 24 June 2021 06:14 AM UTC
CASE 1: either attach dataobject to dw_777 or leave it blank.

CASE 2: dataobject is attached but no row was inserted



following is copy/paset of the messagebox

result is always true





---------------------------

NOT dw_777.RowCount() > 0

---------------------------

TRUE-part

---------------------------

OK

---------------------------





---------------------------

NOT (dw_777.RowCount() > 0)

---------------------------

TRUE-part

---------------------------

OK

---------------------------





CASE 4: Integer age when SetNull(age)

result is always false

following is copy/paste of messagebox



---------------------------

NOT (age > 0)

---------------------------

FALSE-part

---------------------------

OK

---------------------------





---------------------------

NOT age > 0

---------------------------

FALSE-part

---------------------------

OK

---------------------------



CASE 5: Integer age when age = -1

result is always true

following is copy/paste of messagebox



---------------------------

NOT (age > 0)

---------------------------

TRUE-part

---------------------------

OK

---------------------------





---------------------------

NOT age > 0

---------------------------

TRUE-part

---------------------------

OK

---------------------------





if your objective of using NOT is to cover all the sides(including null and less than zero) with just one condition. Certainly that will fail because PowerBuilder IF condition behaviour is not perfect. I already had doubts and found your post. So checked NOT today. :)



Thank you.

  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.