If...Or...Then

David McFarlane mcfarla9 at msu.edu
Thu Sep 23 22:27:16 UTC 2010


Matt,

Well, it always helps to go back and check your 
assumptions as you have done, so kudos for that.

Beyond that, your question strikes me as asking 
something like, "Why was there no ball in the 
box?"  IOW, we are missing any sort of prior 
information about what box, what ball, and how a 
ball would get into the box.  In this case, 
without seeing whatever code is reponsible for 
assigning the values for these Feedback 
attributes, there is nothing we can say about why 
they do not take the desired or expected 
values.  All I can say, based on extensive 
experience of EP as well as a host of other 
programming systems, is that if EP says the value 
of, say, Feedback1 is "1", then that is exactly 
the value that *you* asked EP to give it, so the 
problem is not with EP but in the instructions 
that you gave EP.  As a general rule, machines 
follow our instructions exactly, so the error 
almost always lies in our instructions or our 
understanding & assumptions of how the machine interprets our instructions.

One more hint.  I know that Mich likes to use 
Debug.Print, and in some cases that is just the 
right tool.  I, however, generally prefer to use 
c.SetAttrib to add values to the log and then inspect the values there.

-- David McFarlane, Professional Faultfinder


>update: Here's something interesting. I was in the process of
>rewritting the script and as I was working through it
>I noticed that Attrib("FeedBack1"), ("FeedBack2") and ("FeedBack3")
>weren't always being referenced properly.
>I took out all the script that woudl change any of the programming and
>debugged using this script:
>
>Debug.Print "FeedBack1 was"&c.GetAttrib("FeedBack1")
>Debug.Print "FeedBack2 was"&c.GetAttrib("FeedBack3")
>Debug.Print "FeedBack3 was"&c.GetAttrib("FeedBack3")
>
>what I found was that half the cases the feedback2 was the wrong
>number, feedback1 was wrong only 2x, and
>feedback3 was never referenced incorrectly. have either of run into
>this? I'm currently using 2.8.79 if that makes 3
>any difference.
>
>On Sep 23, 9:26 am, Matt Paffel <mpaf... at gmail.com> wrote:
> > I knew this was going to raise some 'brows when i posted it and I
> > thank you both for the advice.
> > i was actually going to make a table this afternoon when i got into
> > the office just to see if i could work it out
> > on paper first and then retry. I'll let you know how it goes and
> > again, thank you.
> >
> > On Sep 23, 8:52 am, David McFarlane <mcfar... at msu.edu> wrote:
> >
> >
> >
> > > Matt,
> >
> > > I second Mich's sentiment, and will use stronger language -- your code
> > > is a horrible mess!  It is just plain ugly!  People may complain that I
> > > harp too much on the virtue of making code "beautiful", but I find that
> > > making code beautiful also often makes it just work better, and many
> > > code problems result just from ugliness.  So...
> >
> > > - Your code is yet another ugly case of using multiple If...End If
> > > instead of If...ElseIf...Else...End If.  I will leave this as an
> > > exercise for you.  See the online E-Basic Help, and my many other
> > > complaints about this here on the Google Group.
> >
> > > - Better yet, as Mich hinted, see if you can cast this into a
> > > Select...Case structure.
> >
> > > - As Mich also said, use parentheses liberally.  I just had a private
> > > argument with Brandon Cernicky at PST about this very issue, you prove
> > > my point that more parentheses are generally desirable.
> >
> > > - Even better, looking at your code it looks like you actually have a
> > > cascade of several different conditions.  In that case, just reorganize
> > > this into a set of nested If...Then or Select...Case.  That could also
> > > eliminate the And clause, possibly 
> more.  So, something along the lines of
> >
> > > Select LotteryChoice.RESP
> > > Case 1
> > >      If ((c.GetAttrib("FeedBack1") = "0") OR _
> > >          (c.GetAttrib("FeedBack2") = "0") OR _
> > >          (c.GetAttrib("FeedBack3") = "0")) Then _
> > >          Set Slide1.ActiveState = "Default1"
> > >      ....
> > > Case 2
> > >      ....
> > > Case 3
> > >      ....
> > > Case Else
> > >      MsgBox "Invalid LotteryChoice.RESP"
> > > End Select
> >
> > > - Finally, before you even set about to code this any further, first sit
> > > down and make a complete logic table of all the combinatoric conditional
> > > possibilities and the desired result for each combination.  You have a
> > > small finite set of conditions, so this should not take much trouble.  I
> > > do this all the time whenever I face a similar situation, it really
> > > helps to untangle the logic and then I can code it rationally and
> > > quickly.  And if you do not understand what I am talking about, then
> > > take a class that covers propositional (i.e., Boolean) logic and
> > > combinatorics, its not that hard.
> >
> > > -- David McFarlane, Professional Faultfinder
> >
> > > Michiel Spape wrote:
> > > > Hi,
> > > > It gives me headache just looking at it! 
> I'm sure David mcF would be better at cleaning this up, but:
> > > > 1. try to separate multiple AND/ORs using 
> brackets, unless you're REALLY sure about 
> eBasic's priority: does AND go before =, does 
> equal go before OR, does AND go before OR? I'm 
> assuming you mean IF (LotteryChoice.RESP = "1" 
> and (c.GetAttrib("Feedback1") = "0" or 
> c.GetAttrib("Feedback2") = "0" or c.GetAttrib("Feedback3") = "0") then.
> > > > 2. AND ...(c.GetAttrib("Feedback1") = "0" OR ... etc
> > > > Is the same as c.GetAttrib("Feedback1") * 
> c.GetAttrib("Feedback2") * c.GetAttrib("Feedback3") = 0. Awesome trick, no?
> > > > 3. how about:
> > > > ----
> > > > If (c.GetAttrib("FeedBack1") * 
> c.GetAttrib("FeedBack2") * c.GetAttrib("Feedback3")) = 0 then
> > > >   Set Slide1.ActiveState = "Default" & 
> LotteryChoice.RESP ' ...assuming it can be 1 to 3
> > > > End if
> > > > ....
> > > > 4. Do stuff with else and cases. Also, you might wish to nest bits.
> > > > 5. The problem, if you say every IF here 
> turns out wrong is indeed either in your ifs, 
> so you need to clean those up, or in the 
> premises (LotteryChoice.RESP, 
> c.GetAttrib("Feedback")). Why don't you 
> debug.print what the answer to the premises is?
> > > > Debug.print "LotteryChoice.RESP was " & LotteryChoice.RESP
> > > > Debug.print "Feedback1 was: " & c.GetAttrib("Feedback1").
> > > > If it so happens that these are correctly 
> found at the level of your script, and your IF 
> statements still all turn false, then your IF 
> statements are false, so your IF-THENs are not 
> working (I also make messy ones from time to time!).
> > > > Cheers,
> > > > Mich
> >
> > > > If LotteryChoice.RESP = "1" And c.GetAttrib("FeedBack1") = "0"
> > > >  OR c.GetAttrib("FeedBack2") = "0" OR c.GetAttrib("FeedBack3") = "0"
> > > > Then
> > > >  Set Slide1.ActiveState = "Default1"
> > > > End If
> > > > If LotteryChoice.RESP = "2" And c.GetAttrib("FeedBack1") = "0" OR
> > > > c.GetAttrib("FeedBack2") = "0" OR c.GetAttrib("FeedBack3") = "0" Then
> > > >  Set Slide1.ActiveState = "Default2"
> > > > End If
> > > > If LotteryChoice.RESP = "3" And c.GetAttrib("FeedBack1") = "0" OR
> > > > c.GetAttrib("FeedBack2") = "0" OR c.GetAttrib("FeedBack3") = "0" Then
> > > >  Set Slide1.ActiveState = "Default3"
> > > > End If
> > > > If LotteryChoice.RESP = "1" And c.GetAttrib("FeedBack1") = "1" OR
> > > > c.GetAttrib("FeedBack2") = "1" OR c.GetAttrib("FeedBack3") = "1" Then
> > > >  Set Slide1.ActiveState = "Victory1"
> > > > End If
> > > > If LotteryChoice.RESP = "2" And c.GetAttrib("FeedBack1") = "1" OR
> > > > c.GetAttrib("FeedBack2") = "1" OR c.GetAttrib("FeedBack3") = "1" Then
> > > >  Set Slide1.ActiveState = "Victory2"
> > > > End If
> > > > If LotteryChoice.RESP = "3" And c.GetAttrib("FeedBack1") = "1" OR
> > > > c.GetAttrib("FeedBack2") = "1" OR c.GetAttrib("FeedBack3") = "1" Then
> > > >  Set Slide1.ActiveState = "Victory3"
> > > > End If
> > > > If LotteryChoice.RESP = "1" And c.GetAttrib("FeedBack1") = "2" OR
> > > > c.GetAttrib("FeedBack2") = "2" OR c.GetAttrib("FeedBack3") = "2" Then
> > > >  Set Slide1.ActiveState = "Lose1"
> > > > End If
> > > > If LotteryChoice.RESP = "2" And c.GetAttrib("FeedBack1") = "2" OR
> > > > c.GetAttrib("FeedBack2") = "2" OR c.GetAttrib("FeedBack3") = "2" Then
> > > >  Set Slide1.ActiveState = "Lose2"
> > > > End If
> > > > If LotteryChoice.RESP = "3" And c.GetAttrib("FeedBack1") = "2" OR
> > > > c.GetAttrib("FeedBack2") = "2" OR c.GetAttrib("FeedBack3") = "2" Then
> > > >  Set Slide1.ActiveState = "Lose3"
> > > > End If
> >
> > > > Michiel Spap�
> > > > Research Fellow
> > > > Perception & Action group
> > > > University of Nottingham
> > > > School of Psychology
> > > >www.cognitology.eu
> >
> > > > -----Original Message-----
> > > > From: e-prime at googlegroups.com 
> [mailto:e-prime at googlegroups.com] On Behalf Of Matt Paffel
> > > > Sent: 22 September 2010 22:35
> > > > To: E-Prime
> > > > Subject: If...Or...Then
> >
> > > > Hello
> >
> > > > I have Multiple slideslates that I'm tring to change based on the
> > > > script below, however the script isn't performing as I'd like it to.
> >
> > > > The message from the output window after debugging states:
> >
> > > > 3Lose3
> > > > False
> > > > 2Lose3
> > > > False
> > > > 1Lose3
> > > > False
> >
> > > > This tells me that it's collecting the responses correctly and setting
> > > > a slide state but it looks as though the program is going through the
> > > > arguments and declaring them all false, which is not the case. Is
> > > > there something I need to include as the arguments make use of the
> > > > "OR" statement or is something else such as my overzealous use of the
> > > > If...Then statement?
> >
> > > > Note: I've added indents here to make it easier to look at.
> >
> > > > If LotteryChoice.RESP = "1" And c.GetAttrib("FeedBack1") = "0"_
> > > >  OR c.GetAttrib("FeedBack2") = "0" OR c.GetAttrib("FeedBack3") = "0"
> > > > Then
> > > >  Set Slide1.ActiveState = "Default1"
> > > > End If
> > > > If LotteryChoice.RESP = "2" And c.GetAttrib("FeedBack1") = "0" OR
> > > > c.GetAttrib("FeedBack2") = "0" OR c.GetAttrib("FeedBack3") = "0" Then
> > > >  Set Slide1.ActiveState = "Default2"
> > > > End If
> > > > If LotteryChoice.RESP = "3" And c.GetAttrib("FeedBack1") = "0" OR
> > > > c.GetAttrib("FeedBack2") = "0" OR c.GetAttrib("FeedBack3") = "0" Then
> > > >  Set Slide1.ActiveState = "Default3"
> > > > End If
> > > > If LotteryChoice.RESP = "1" And c.GetAttrib("FeedBack1") = "1" OR
> > > > c.GetAttrib("FeedBack2") = "1" OR c.GetAttrib("FeedBack3") = "1" Then
> > > >  Set Slide1.ActiveState = "Victory1"
> > > > End If
> > > > If LotteryChoice.RESP = "2" And c.GetAttrib("FeedBack1") = "1" OR
> > > > c.GetAttrib("FeedBack2") = "1" OR c.GetAttrib("FeedBack3") = "1" Then
> > > >  Set Slide1.ActiveState = "Victory2"
> > > > End If
> > > > If LotteryChoice.RESP = "3" And c.GetAttrib("FeedBack1") = "1" OR
> > > > c.GetAttrib("FeedBack2") = "1" OR c.GetAttrib("FeedBack3") = "1" Then
> > > >  Set Slide1.ActiveState = "Victory3"
> > > > End If
> > > > If LotteryChoice.RESP = "1" And c.GetAttrib("FeedBack1") = "2" OR
> > > > c.GetAttrib("FeedBack2") = "2" OR c.GetAttrib("FeedBack3") = "2" Then
> > > >  Set Slide1.ActiveState = "Lose1"
> > > > End If
> > > > If LotteryChoice.RESP = "2" And c.GetAttrib("FeedBack1") = "2" OR
> > > > c.GetAttrib("FeedBack2") = "2" OR c.GetAttrib("FeedBack3") = "2" Then
> > > >  Set Slide1.ActiveState = "Lose2"
> > > > End If
> > > > If LotteryChoice.RESP = "3" And c.GetAttrib("FeedBack1") = "2" OR
> > > > c.GetAttrib("FeedBack2") = "2" OR c.GetAttrib("FeedBack3") = "2" Then
> > > >  Set Slide1.ActiveState = "Lose3"
> > > > End If- Hide quoted text -
> >
> > - Show quoted text -
>
>--
>You received this message because you are 
>subscribed to the Google Groups "E-Prime" group.
>To post to this group, send email to e-prime at googlegroups.com.
>To unsubscribe from this group, send email to 
>e-prime+unsubscribe at googlegroups.com.
>For more options, visit this group at 
>http://groups.google.com/group/e-prime?hl=en.

-- 
You received this message because you are subscribed to the Google Groups "E-Prime" group.
To post to this group, send email to e-prime at googlegroups.com.
To unsubscribe from this group, send email to e-prime+unsubscribe at googlegroups.com.
For more options, visit this group at http://groups.google.com/group/e-prime?hl=en.



More information about the Eprime mailing list