Jump to content
Macro Express Forums

Help with logic. Mix AND and OR?


Cory
 Share

Recommended Posts

I'm having a block on mixing ANDs and ORs. Three cars, two drivers. I thought it would look like the following but it's not working.

 

If Car = Corvette

OR

If Car = Porsche

And

If Car does not contain Blonde

Wave

Else

Don't wave

Endif

 

What I want is the following. How would you structure it? I know I could nest but I don't want to "Don't wave" twice.

 

Corvette with Blonde = Don't wave

Porsche with Blonde = Don't wave

Ferrari with Blonde = Don't wave

Corvette with Redhead = Wave

Porsche with Redhead = Wave

Ferrari with Redhead = Don't wave

 

And if someone could explain how ORs and ANDs combine I would appreciate it.

Link to comment
Share on other sites

Hi Cory: First, thanks for all your help and comments in the past. I'm not always good at saying thanks right away. What I have done in situations like this I have the first IF OR if true, then have it hit another IF for the and. That way, if the first isn't true, it bypasses it, but if it is it goes to the next IF and if that is true will do that, else bypass it. It uses more scripting but I have found it works better. I'm sure someone else has better ideas.

 

Here is a sample script.

<IFVAR2:1:73:1:09><OR><IFVAR2:1:74:1:12><MSD:250><IFVAR2:2:01:1:3><MSD:250><TEXTTYPE:You have to look at this manually><MSD:250><TEXTTYPE:<NUMENTER><ARROW DOWN>><MSD:250><ELSE><MSD:250><TEXTTYPE:<ARROW DOWN>><MSD:250><ENDIF>

Link to comment
Share on other sites

Here is what I came up with from your description. I used a truth table to come up with the possible outcomes:

 

        Corvette               Porsche            Ferarri
Blonde      0                    0                   0
Red         1                    1                   0

 

This led to this code:

 

// T1 = Car Type
// T1= Hair Color
Multiple Choice Menu: Car Type
Multiple Choice Menu: Hair
If Variable %T1% contains "A"
 OR
If Variable %T1% contains "B"
 AND
If Variable %T2% <> "A"
 Text Box Display: Wave
Else
 Text Box Display: No Wave
End If

 

I have also attached a copy of the macro for you to look at.

Logic.mex

Link to comment
Share on other sites

Thanks JohnBoy. I know I can do it by nesting but there's a complication that's difficult to explain having to do with the action performed in the true and false (Else) sections and even though I can use nested it's inelegant and I figured I should know how to combine these. I learned it once when I took a class in Pascal but that was 20 years ago now! No worries, I can do some experiments that will tell me what I need to know. Thanks!

Link to comment
Share on other sites

Jason: That's weird. I have a sample macro that on the surface looks just like this but returns false for everything. I'm going to have to look very carefully at both and get back on this one. Must have done something stupid and assumed it was a logic problem. Thanks for the sample.

 

Jason do you know of a simple plain English description of how different condition combiners are processed?

Link to comment
Share on other sites

I am an idiot. I had made my sample then I change to use the text instead of ABC because I was confused as to which meant what but I forgot to change the multiple choice to "Save Item Text" and everything was coming up false! So I had the logic right but I wasn't implementing properly. Ug. Thanks for all your help all the same.

 

I'm still confused about what the rule is. With three conditions and an OR 1/3, 2/3, or 3/3 need to be true and for AND 3/3 need be true. But mixed.... I did a truth table on my real data and found that that we needed 2/3 which is the best one can do in their case. All 1/3 and 0/3 fail. But is it an accumulative thing or linear? I'm thinking that one considers the first connective by itself and establish a T/F then that result is used in the next connective. Is that correct? Or is there an order of precedence like in algebraic order of ops like 1+2*3 and whether the answer is 7 or 9.

Link to comment
Share on other sites

Never mind, I figured it out. I tried putting the AND first and running the table and get different results and it matches with the set I get by comparing the first connective and then comparing the second connective with it's validity.

Link to comment
Share on other sites

If Car = Corvette

OR

If Car = Porsche

And

If Car does not contain Blonde

Wave

Else

Don't wave

Endif

Without brackets or pre-agreed priorities on AND and OR, the above is ambiguous!

 

It could mean

If Car = Corvette, then wave

If Car = Porsche with no blonde, then wave

Else don't wave

So we wave ONLY at all corvettes, OR all porsches with blondes

 

It could also mean

If Car = Corvette or Car = Porsche, and the car does not contain a blonde, then wave

Else don't wave

So we wave ONLY if there's a blonde in a corvette OR a porsche

 

So I suggest

If Car = Corvette

OR

If Car = Porsche

If car does not contain blonde

then wave

else

don't wave

endif

else

don't wave

endif

Link to comment
Share on other sites

Thanks Paul, this is exactly what I was concerned about. Depending on the order of ops you can get different results. But I now see that ME processes them sequentially. IOW it's like a non-scientific calculator. Like in my mathematic example 1+2*3= ME would take 1+2 and get 3, then take 3*3 to get 9. I did several experiments to verify this and it was confirmed empirically. In my macro 9 was the answer I was looking for so it worked perfectly. I got what I wanted early on but I wanted to know the rule for future projects. Now that I know the model I can predict.

 

Now I got to figure out the XOR when I have a few minutes...

 

Hey, nice to hear from you again Paul! I hope things are well down there.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...