Handling boolean expressions

Just starting out? Need help? Post your questions and find answers here.
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

Sorry, I still don't understand... Are you aming at this Macro given in the german help?

Code: Select all

  Macro Is(Bool) 
    (0 Or (Bool)) 
  EndMacro 
Kaeru, you're welcome to wite a PM, if neccessary.
PB 4.30

Code: Select all

onErrorGoto(?Fred)
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

AND51 wrote:Unfortunately, I don't really understand...? Can you explain it in other words again and/or give me an example code?
Ok, these are the rules:
Relational operators are: <, >, =, >=, <=, <>
Boolean operators are: And Or Not Xor
The result of relational and boolean operators can only be given to If, While, Until, And, Or, Not, ElseIf or XOr. This means you can't do ((a=b)+2) because then result of the relational operator is given to the + operator.

Forbidden:
A = B = C ; The result of B = C is not given to If, While, Until, And, Or, Not, ElseIf or XOr.

if (B = C) * D ; The result of B = C is given to the * operator, which is not on this list: If, While, Until, And, Or, Not, ElseIf, XOr.

Allowed:
IF B = C * D ; Multiply, then compare and use the result of the comparision in the IF statement.

IF B = C And B = D ; The result of the ='s are given to AND, the result of the AND is given to the IF.
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

Ah ok, thanks a lot! Now I understand! :D

however, this means that calculating with bools is not possible...
PB 4.30

Code: Select all

onErrorGoto(?Fred)
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

that's right, Trond.

@AND

1. to some Macro you can not only pass Numbers, but Expressions.
to shut this expressions it MUST be enclosed in Brackets.

2. adding a Compare-Operator to some closed Expression will make the new term a Boolean Expression.
A Boolean Expression ALWAYS have to be enclosed in brackets,
to tell the Compiler its an Expression and not a Comparison.

3. In PB there is a trick: a Boolean Expression can work, if you add a Boolean Operation.
as Freak already said: this is a Trick!
you can't claim any support for a trick.

4. This new Expression should also be enclosed in Brackets.

this should tell you, that you left out much too much Brackets, so no wonder your Code doesn't work.

and I repeat once more:
It is a TRICK, not a Feature!

[edit]
...forgot the "-"...
it doesn't work with StrQ().

Code: Select all

Macro XAbs(Exp) 
  ((Exp)*((((Exp)>0) Or 0)*2-1))
EndMacro

a.l = -512874

Debug XAbs(a)

b.l = XAbs(a)

Debug Str(b)
oh... and have a nice day.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

>calculating with bools is not possible...
You understood it right, it's exactly what I said (except I had to use a bit more space to say it)! :lol:
Post Reply