"Type Mismatch" error upon slide timeout

2,056 views
Skip to first unread message

Erin

unread,
Sep 25, 2012, 3:17:05 PM9/25/12
to e-p...@googlegroups.com
Hello everyone,
I have an experiment where the subject has 3 seconds to make a response each trial, after which the trial times out.  On the Feedback slide, I want to display the number of trials completed, not counting trials that timed out.  

To do this, I added an inline to my experiemnt. I noticed in my data output that when Stimulus.RESP = 1, the trial has been completed. So, this is the inline text I used:

If Stimulus.RESP = 1 Then
nPoints = nPoints + 1 
Else
nPoints = nPoints + 0
End If
c.SetAttrib "CurrentPoints", nPoints

I also went to view -> script, and added "Dim nPoints as integer" in the user script. 

When I run my experiment, it successfully displays a trial count on the feedback slide as long as I make either correct or incorrect responses. However, as soon as I let a trial time out, I get the following error, and the program terminates:

The following Runtime error occurred:
Type Mismatch
line: 640
error number: 13

I have tried adjusting a few things, but with no success.  Does anyone have experience getting around this error? thanks so much

Erin

David McFarlane

unread,
Sep 25, 2012, 3:48:23 PM9/25/12
to e-p...@googlegroups.com
Erin,

Sigh. Please, please, please folks: (1) Do *not* apply any
formatting to text in your posts, it makes it illegible in some
e-mail readers. Just use plain text. (2) OTOH, *do* indent your
code fragments for readability, e.g.,

If Stimulus.RESP = 1 Then
nPoints = nPoints + 1
Else
nPoints = nPoints + 0
End If
c.SetAttrib "CurrentPoints", nPoints

Now, to start with, why in the world would you have a line like

nPoints = nPoints + 0

which produces absolutely no effect?! The following simplified code
would do the same:

If (Stimulus.RESP = 1) Then nPoints = nPoints + 1
c.SetAttrib "CurrentPoints", nPoints

Now, to your problem. The RESP property of Stimulus has type String,
not Integer. Because VBA/E-Basic, when possible, does automatic type
conversion (which just allows programmers to get sloppy), that works
fine as long as RESP happens to contain text that will convert to an
integer. But when you get no response, RESP contains the null sting
"", and that does *not* convert to an integer. Thus, the "Type
Mismatch" error, easily understood by those of us who grew up with
proper strongly-typed languages (e.g., Fortran, Pascal, C).

The solution? Here are better tests for *presence* of a response:
- If (x.RESP <> "") ...
- If (Len(x.RESP) > 0) ..., or, If Len(x.RESP) ...
- If (x.RTTime <> 0) ..., or, If (x.RTTime) ...
- If (x.InputMasks(1).Count > 0) ...,
or, If x.InputMasks(1).Count ... (but only for given mask)

Simply invert these to make tests for *absence* of a response. And
as indicated by these examples, because VBA/E-Basic treats 0 as False
and any non-0 value as True, in some cases you need not make the
comparison test explicit (although most users may find that
discomforting). (I used to also include the test "If (x.RT) ...",
but I recently discovered that, in the unlikely case that RTTime =
OnsetTime, RT would be 0 even with a response.)

So in your case, this comes down to just, e.g.,

If Stimulus.RTTime Then nPoints = nPoints + 1
c.SetAttrib "CurrentPoints", nPoints

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

/----
Stock reminder: 1) I do not work for PST. 2) PST's trained staff
take any and all questions at
http://support.pstnet.com/e%2Dprime/support/login.asp , and they
strive to respond to all requests in 24-48 hours -- this is pretty
much their substitute for proper documentation, so make full use of
it. 3) In addition, PST takes questions at their Facebook page
(http://www.facebook.com/pages/Psychology-Software-Tools-Inc/241802160683
), and offers several instructional videos there and on their YouTube
channel (http://www.youtube.com/user/PSTNET ) (no Twitter feed yet,
though). 4) If you do get an answer from PST staff, please extend
the courtesy of posting their reply back here for the sake of others.
\----

Erin

unread,
Sep 26, 2012, 2:47:24 PM9/26/12
to e-p...@googlegroups.com
David,
Thank you very much for the help and the detailed explanation about type.  I had never been exposed to programming before using E-Prime, so the explanation is very helpful.  Thanks again!!

Erin

Chloe Jost

unread,
Sep 19, 2018, 4:05:49 PM9/19/18
to E-Prime
Hi all.

I am having a similar issue to Erin, in which when I make a response to the Slide my experiment continues normally, but if I do not make a response I get this same error code (Type Mismatch, number 13). In this experiment, the subject has limited time to simply rate an image on the slide, and if they do not respond it will time out and move on. Any thoughts? I will include the section that the error message is citing as the issue:

If Stim.RESP=2 Then
resp=c.GetAttrib("ResponseR")
hand="Right"
ElseIf Stim.RESP=7 Then
resp=c.GetAttrib("ResponseL")
hand="Left"
Else
resp="NA"
hand="NA"
End If

c.SetAttrib "Response", resp

c.SetAttrib "Hand", hand

Thank you so much,
Chloe

McFarlane, David

unread,
Sep 20, 2018, 11:32:03 AM9/20/18
to e-p...@googlegroups.com
Michiel Spape already provided a fine answer to this in a separate
thread at groups.google.com/d/topic/e-prime/uRAcjdfFbK , but I thought I
would give a brief response here because it sort of wraps up the lesson
on "Type mismatch" that started earlier in this thread. We did not
quite finish the lesson there because, in Erin's case, she wanted to
know only whether or not the subject made a response, and the solution
to that ended up sidestepping the whole type matching issue.

But Chloe wishes to know if the response matches some specific values,
so here we have to meet the type matching issue head on, and the answer
is simple. Stim.RESP hold a value of type string, e.g., "a" or "2" or
even "", instead of a value of some actual numeric type, e.g., 2. So to
compare RESP to a numeric value, we have to provide the numeric value as
a string, and we can do that merely by enclosing the value within
double-quotes, e.g.,

If (Stim.RESP = "2") Then

That should do it.

---------------
David McFarlane
E-Prime® 2.0 training online:
psychology.msu.edu/workshop-and-additional-course/e-prime-introduction-to-programming-computerized-behavioral-tasks
Twitter: @EPrimeMaster (twitter.com/EPrimeMaster)

McFarlane, David

unread,
Sep 20, 2018, 11:35:04 AM9/20/18
to e-p...@googlegroups.com
Sorry, I gave a bad link to the thread with Michiel's fine answer, this
one should work: groups.google.com/d/topic/e-prime/uRAcjdfFbKA
Reply all
Reply to author
Forward
0 new messages