Complex Logical Statements (Boolean Operator problem)

Hints, tips and tricks for newbies

Moderators: JRL, Dorian (MJT support)

Post Reply
winstein
Pro Scripter
Posts: 84
Joined: Mon Nov 26, 2012 3:44 pm

Complex Logical Statements (Boolean Operator problem)

Post by winstein » Mon Mar 11, 2013 6:18 am

There is a type of logical statement that I have trouble getting to work, which is Boolean-related, because most of the time, it results in an error or it's not working.

In the following statement, I want to apply an "OR" statement for three different relational conditions, but I couldn't get the "OR" to work. I tried applying brackets ("{""}") into each relational conditions, but it didn't work either. Here's part of the code I have trouble with (the pic is there because the code couldn't display the code properly):

Image

Code: Select all

If>%ini_datePart2%<>Y OR %ini_datePart2%<>M OR %ini_datePart2%<D>%ini_datePart3%=M OR %ini_datePart1%=M
        If>%ini_datePart3%=D OR %ini_datePart1%=D
            Let>ini_datePart2=Y
        Else
            Let>ini_datePart2=D
        EndIf
    Else
        Let>ini_datePart2=M
    EndIf
EndIf
What should I do to get the boolean operator to work properly?

Thanks for reading.

(For extra points, is there a more efficient way to arrange the Day, Month and Year while avoiding duplicate fields?)
PPQ

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Mar 11, 2013 10:05 am

1. Complex expressions should be delineated with { .... }
2. Each part of a logical expression must be in parentheses so it is clear what must be ORd against what.
3. Strings in complex expressions should be quoted.

So the correct syntax is (probably):

Code: Select all

If>{(%ini_datePart2%<>"Y") OR (%ini_datePart2%<>"M") OR (%ini_datePart2%<>"D")}
    If>{(%ini_datePart3%="D") OR (%ini_datePart1%="D")} 
       ...
I say probably because that looks a bit confused, shouldn't your ORs be ANDs.

Are you trying to say if ini_datePart2 is not Y, and is not M and is not D? In otherwords are you trying to say if ini_datePart2 is anything other than a Y an M or D? If so you should be saying:

Code: Select all

If>{(%ini_datePart2%<>"Y") AND (%ini_datePart2%<>"M") AND (%ini_datePart2%<>"D")}
    If>{(%ini_datePart3%="D") OR (%ini_datePart1%="D")} 
       ...
So if ini_datePart2 is not Y and not M and not D (and therefore can be anything else) now check if part3 is D or part1 is D and if so continue ...

Is that what you mean?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

winstein
Pro Scripter
Posts: 84
Joined: Mon Nov 26, 2012 3:44 pm

Post by winstein » Tue Mar 12, 2013 1:05 am

Yeah, that was a mistake on my part. It should have been AND because I wanted to make sure the DatePart is not Y, M and D.

Anyway, thank you for your help, because it seems to be working for me now.
PPQ

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts