How to control flow within conditions?

36 views
Skip to first unread message

Bella Do

unread,
Oct 5, 2017, 9:21:48 AM10/5/17
to E-Prime
Hello, 
I'm a student in Educational Psychology and I'm trying to design an experiment using E-prime.
The participants will have to choose between two ways of study method by pressing either "1" or "2".
And the next procedure will depend on their selection.
So after the guideline, I added Inline with the following script:
Dim answer as String
If answer = "2" then
Goto Label1
End If
However, when I run the script, it didn't go to Label1 even after I pressed 2. It just went to the next slide in the procedure without jumping.
Is there anyone know the problem with my script? And what can I do to improve it?
Thank you! I really appreciate your help!!

Michiel S-Spape

unread,
Oct 5, 2017, 10:20:43 AM10/5/17
to e-p...@googlegroups.com

Hi Bella,

By writing “Dim Answer as String” you create a new variable, called Answer, and set it to “”. It will therefore never be “2”.

Instead, let’s say your “guideline” is called TextGuideLine,

Writing between the Dim and If:

Answer = TextGuideLine.RESP

…should make it work.

The variable Answer isn’t necessary though: just

If TextGuideLine.RESP = “2” then … should already work.

Best,

Michiel

--
You received this message because you are subscribed to the Google Groups "E-Prime" group.
To unsubscribe from this group and stop receiving emails from it, send an email to e-prime+u...@googlegroups.com.
To post to this group, send email to e-p...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/e-prime/10848cde-ce79-4145-b996-bb7dc4e72e37%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


David McFarlane

unread,
Oct 5, 2017, 11:01:38 AM10/5/17
to e-p...@googlegroups.com

David McFarlane

unread,
Oct 5, 2017, 11:10:54 AM10/5/17
to e-p...@googlegroups.com
Darn, forgot to edit that link to avoid my university's link mangling.
Here it is again in more readable (though perhaps not clickable) form:
groups.google.com/d/topic/e-prime/Liej8Ik83sU/

-- David McFarlane

Bella Do

unread,
Oct 5, 2017, 11:34:56 AM10/5/17
to E-Prime
Thank you guys so much for your help!! ^^
I did as you said and it worked perfectly well.
Thanks again!

Bella Do

unread,
Oct 17, 2017, 8:13:46 AM10/17/17
to E-Prime
Hello
In my experiment, I would like to make the participants select either "1" or "2" before moving to the next section. If they enter any other number, they would have to go back to the selection page. Hence, I wrote the following script in Inline.
If Slide13.RESP = "2" + "{ENTER}" Then
GoTo Label1
End If 
If Slide13.RESP = "1" + "{ENTER}" Then 
GoTo Label3
End If
If Slide13.RESP = "12" + "{ENTER}" Then
GoTo Label4
End If 
If Slide13.RESP = "21" + "{ENTER}" Then
GoTo Label4
End If 
If Slide13.RESP = "{ENTER}" Then
GoTo Label4
End If 
Label4 is going back to selection page where they would have to enter the number again.
In the Allowable part, I wrote down only {ENTER}12{BACKSPACE}
However, there is one problem. I can't prevent them to enter some other weird numbers such as:  1212 or 2121 or 23 or 13.
If they input any weird number but having either "1" or "2" in it OR input even weirder number made from "1" and "2" such as 1221212, they can still move to the next section.

That's why I wonder whether there is a way to write script so that if they input any number other than "1" or "2", they would have to go to selection page again and re-enter the number?
I'm looking forward to your response. Thank you so much! 

David McFarlane

unread,
Oct 17, 2017, 10:30:45 AM10/17/17
to e-p...@googlegroups.com
The solution is mindlessly simple, and would be taught in any
Introduction to Computer Programming course, so I highly recommend that
you take such a course ASAP. Until you do that you will face many other
hurdles. Or just get out any introductory computer programming text
(try the "for Dummies" series) with any suitable language (e.g., Python,
JavaScript) and teach yourself. We are talking about learning basic
computer programming principles here.

That said, here is an example solution using If-Then:

If Slide13.RESP = "2{ENTER}" Then GoTo Label1
If Slide13.RESP = "1{ENTER}" Then GoTo Label3
GoTo Label4

Normally I would use If-Then-ElseIf there, but since each Goto already
short-circuits the If-Then sequence I left each of these as single-line
If-Thens.

Here it is using the more elegant Select Case structure (see that topic
in the E-Basic Help facility):

Select Case Slide13.RESP
Case "2{ENTER}"
GoTo Label1
Case "1{ENTER}"
GoTo Label3
Case Else
GoTo Label4
End Select

Case-Select often makes things easier to read, but in this case it does
seem a bit of overkill.

Of course, you could also simplify this by only allowing 1-character
responses in the first place, i.e., move on as soon as the subject
presses either "1" or "2". Many ways to skin this cat.

And just to grouse a little more, you should use meaningful names for
everything, instead of generic "Slide13", "Label1", etc. And you need
to learn how to properly indent your code!

And I cannot stress this enough -- please take a course in basic
computer programming.

-- David McFarlane


On 2017-10-17 8:13 AM, Bella Do wrote:
> Hello
> In my experiment, I would like to make the participants select either "1"
> or "2" before moving to the next section. If they enter any other number,
> they would have to go back to the selection page. Hence, I wrote the
> following script in Inline.
> *If Slide13.RESP = "2" + "{ENTER}" Then*
> *GoTo Label1*
> *End If *
> *If Slide13.RESP = "1" + "{ENTER}" Then *
> *GoTo Label3*
> *End If*
> *If Slide13.RESP = "12" + "{ENTER}" Then*
> *GoTo Label4*
> *End If *
> *If Slide13.RESP = "21" + "{ENTER}" Then*
> *GoTo Label4*
> *End If *
> *If Slide13.RESP = "{ENTER}" Then*
> *GoTo Label4*
> *End If *

Bella Do

unread,
Oct 17, 2017, 11:06:47 AM10/17/17
to E-Prime
Thank you so much. I will try to read the books that you recommended asap!


Reply all
Reply to author
Forward
0 new messages