PxPlus User Forum

Twitter Twitter Twitter

Author Topic: Compound IF expressions  (Read 1261 times)

James Zukowski

  • Diamond Member
  • *****
  • Posts: 297
    • View Profile
Compound IF expressions
« on: September 11, 2019, 11:51:26 AM »
Using AND and OR in IF conditions seem to throw Syntax Errors (#20) in certain situations, e.g.,

if A$ and Anything_Else then print "OK"

Evidently, the string expression without a relational operator and comparison value has to be stand-alone:

if A$ then if Anything_Else then print "OK"

Does anyone know if this is the correct operation, or if both of these should work...?

Thanks, all!
James Zukowski
Sr. Developer - J&E

BRAND>SAFWAY
Brand Industrial Services

Frank Dreßler

  • Guest
Re: Compound IF expressions
« Reply #1 on: October 04, 2019, 12:59:40 PM »
The and operator is defined for numeric operands only. That is why x$ and y is an invalid expression. It's an operator like any other: You can write something like result = x and y. If the condition expression in an if statement is a string, it behaves like if not(nul(x$)) ... So to get the same effect like if x$ if y ... you can write if not(nul(x$)) and y .... You could also write if len(b$) and y or if b$<>"" and y but that's only checking for the empty string. if x$ also considers space-only strings false. It is also important to note that not(...) does only negate the boolean value of its parameter if it is numeric. When a string is passed to not(...) it inverts all bits. This means if x$ is not the inverse of if not(x$). So when using strings in a compound if expressions, you usually want to use nul(x$) or not(nul(x$)).