Re: End Sub while expecting End If

1,138 views
Skip to first unread message
Message has been deleted

Anne-Wil

unread,
Jan 28, 2015, 7:18:52 AM1/28/15
to e-p...@googlegroups.com
Hi Camila,

If -then statements come in two forms in e-prime. If F and THEN are written on the same line (as in: If c.getAttrib ("Correct") = 6 Then CounterStimulusType6 = CounterStimulusType6 + 1) e-prime will execute them as they are encountered. This way you can 'attach' one 'THEN action' to an 'IF'. However, if you need more 'THEN actions',  or if you also the ELSE option as you do, you'll need to 'break' the IF THEN line over multiple lines. In that case e-prime requires an 'END IF' after the complete set of  THEN/ELSE actions attached to a single "IF"-statement. In your script his happens when you start redirecting e-prime to labels. For instance:

 If (CounterStimulusType1 >= 6) And (CounterStimulusType2 >= 6) Then
GoTo LabelShape
Else
GoTo LabelColor

^  this piece of code needs to end with an END IF for e-prime to accept. HOWEVER... it may be the canse that (and no e-prime on the computer were I am no so can't test but I thin that) as soon as the GOTO labelshape is encountered, the program will move to the label and would not even reach the END IF even if you would add it (not sure, may also be that it starts moving only when it reaches the END IF).

In any case: the simple solution (even though it probably isn't the preferred practice by professional programmers) is to rewrite your statements so that each only takes a single line:

If (CounterStimulusType1 >= 6) And (CounterStimulusType2 >= 6) Then GoTo LabelShape

If(CounterStimulusType2 >= 6) Then GoTo LabelShape

If(CounterStimulusType3 >= 6) Then GoTo LabelShape

If (CounterStimulusType4 >= 6) Then GoTo LabelShape

If (CounterStimulusType5 >= 6) Then GoTo LabelShape

If (CounterStimulusType6 >= 6) Then GoTo LabelShape

GoTo LabelColor

-> if none of the 'counterstimulustypeX' >= 6 are met, the GOTO labelcolor will be reached and e-prime will move there.

Notes: >= may as well just be =, cause I'd guess that the program will not return here once 6 is reached (i.e. >6 cannot occur?). You may want to look into loops to replace an 'x' or other placeholer with the numbers 1-6 and have a briefer piece of code - but that's more aesthetic than anything else. The first line of the above piece (If (CounterStimulusType1 >= 6) And (CounterStimulusType2 >= 6) ) also seems redundant -> if the second part of the IF statement is true ((CounterStimulusType2 >= 6) ) the next line will take care of executing the same THEN action (goto labelshape).

This is just a quick and dirty solution but I hope it gets you going again :)

Best,

Anne-Wil




On Tuesday, 27 January 2015 13:52:17 UTC, Camila Martínez wrote:
Hi,
I am trying to set an experiment with the condition that after 6 correct answers, it jumps to the next Trial Procedure.
I found a script here, I made some changes trying to fix the problem, but it doesn't run, and an error is shown with 'Encountered: End sub, Expecting: End If'
This is the only inline I added to the experiment, and in order to go from one Trial Procedure to the next, I put labels.
 
Dim CounterStimulusType1 As Integer
Dim CounterStimulusType2 As Integer
Dim CounterStimulusType3 As Integer
Dim CounterStimulusType4 As Integer
Dim CounterStimulusType5 As Integer
Dim CounterStimulusType6 As Integer
Trial:
If c.getAttrib ("Correct") = 1 Then CounterStimulusType1 = CounterStimulusType1 + 1
If c.getAttrib ("Correct") = 2 Then CounterStimulusType2 = CounterStimulusType2 + 1
If c.getAttrib ("Correct") = 3 Then CounterStimulusType3 = CounterStimulusType3 + 1
If c.getAttrib ("Correct") = 4 Then CounterStimulusType4 = CounterStimulusType4 + 1
If c.getAttrib ("Correct") = 5 Then CounterStimulusType5 = CounterStimulusType5 + 1
If c.getAttrib ("Correct") = 6 Then CounterStimulusType6 = CounterStimulusType6 + 1
If (CounterStimulusType1 >= 6) And (CounterStimulusType2 >= 6) Then
GoTo LabelShape
Else
GoTo LabelColor
If(CounterStimulusType2 >= 6) Then 
GoTo LabelShape
Else
GoTo LabelColor
If(CounterStimulusType3 >= 6) Then 
GoTo LabelShape
Else
GoTo LabelColor
If (CounterStimulusType4 >= 6) Then
GoTo LabelShape
Else
GoTo LabelColor
If (CounterStimulusType5 >= 6) Then
GoTo LabelShape
Else
GoTo LabelColor
If (CounterStimulusType6 >= 6) Then 'if either one hasn't reached 6
GoTo LabelShape
Else
GoTo LabelColor
End If
 
I have three of this inlines, changing the label names. One for each Trial Procedure.
 
It would be very helpful I you have an idea.
 
Thank you very much,
 
Camila M

Camila Martínez

unread,
Feb 2, 2015, 4:41:22 AM2/2/15
to e-p...@googlegroups.com
Thank you very much for your help!

Camila M
Message has been deleted

victoria...@york.ac.uk

unread,
Jun 27, 2016, 11:44:30 AM6/27/16
to E-Prime
Hi Anne-Wil,

I wonder if you could help me on a GoTo problem...

I have an inline script with the statement 'If ExitNow = 1 Then GoTo EndOfTask' where ExitNow is a global variable and EndOfTask is a slide at the end of my SessionProc. When I generate the script I get the error message 'variable name used as label name', but should label name not just be the name of the object you want to skip to?

Thank you!

Victoria 

David McFarlane

unread,
Jun 27, 2016, 2:40:33 PM6/27/16
to e-p...@googlegroups.com
Victoria,

No. The error message means what it says. A "Goto" must be followed by
a Label, and that Label must then appear somewhere in your Procedure.
This is true of any programming language that has a Goto.

You may find examples of using Goto and Labels in chapters 3 and 5 of
the Users Guide that came with E-Prime. I also have an exercise to show
this in my online course.

---------------
David McFarlane
E-Prime training online:
http://psychology.msu.edu/Workshops_Courses/eprime.aspx
Twitter: @EPrimeMaster (https://twitter.com/EPrimeMaster)

victoria...@york.ac.uk

unread,
Jun 28, 2016, 5:55:20 AM6/28/16
to E-Prime
Hi David,

Thank you for your swift response. I shall have a look at your online exercises and come back to you if I have any troubles with it.

All the best

Victoria
Reply all
Reply to author
Forward
0 new messages