How to display a selected response (selected by press a key in the keyboard)

David McFarlane mcfarla9 at msu.edu
Fri Sep 5 13:59:02 UTC 2014


Oli,

Ah, of course, you still have to cast the result 
of SlideState.Objects() to tell E-Prime what 
*type* of object it is.  You can see an example 
of this in the SlideState.Objects topic of the 
E-Prime Help facility (good to get familiar with 
that facility for lots of reasons!).  So your line should look more like

     Set hitObject = CSlideText(theState.Objects("Text1"))

Hmm, now I find the name of the hit variable 
misleading, as it is not a generic Object but 
rather a SlideText object, and I get very fussy 
about names in programs.  I urge you to rename 
that to something like hitSlideText to better 
reflect its nature.  Typically, I would make a 
variable named "slText" if I wanted a generic 
SlideText variable for general purposes.  Just my personal style.

Best,
-- David McFarlane


At 9/4/2014 10:40 PM Thursday, Oli Chen wrote:
>Thank you very much, David! :)
>It is very nice of you to give such a quick reply!
>
>I understood what you mentioned, and tried to edit the code as you suggested.
>However, there is still the error :( Â and it 
>came from the same line:Â Â Set hitObject = theState.Objects("Text1")
>the error message is "assignment variables and 
>expression are different types"...
>
>I then wandered whether it is because I made some mistake in editing my slide.
>I had a slide with three slideTexts. I added 
>"keyboard" as the device for response, and the 
>allowance is "2", "3", and "4".Â
>the end action is set as "terminate", but i also tried with "none".
>
>I have no idea which part can be wrong...
>do you have any other suggestion or solution?
>
>thanks a lot again!!!
>have a good day!!^______^
>oli:)
>
>
>On Fri, Sep 5, 2014 at 3:41 AM, David McFarlane 
><<mailto:mcfarla9 at msu.edu>mcfarla9 at msu.edu> wrote:
>You did not say what line caused the error 
>message, but I suspect it came up for one of the 
>"hitObject = ..." lines.  That error message, 
>"object does not have an assignable default 
>property", typically comes up when you forget to 
>put "Set" in front of the assignment statement 
>for an object variable (obviously -- NOT!).  In 
>E-Basic/VBA, you must use Set at the start of 
>any assigment statement for an object variable, 
>and you must *not* use Set at the start of any 
>assignment statement for ordinary varibles (you 
>may in this case preface the assigment with the 
>arcane "Let" keyword, otherwise that is 
>implied).  (Yes, this is an absurd rule, 
>peculiar to VBA, and provides many headaches with no compensating advantages.)
>
>So your hitObject assigment statements should read like
>
>Â  Â  Set hitObject = theState.Objects("Text1")
>
>Also note that for cases "3" & "4" you switch to 
>using ResponseSlide.Name, which I think will not work.
>
>That said ...  What happens if RESP is not 2, 
>3, or 4?  Of course, your input mask Allowable 
>may guarantee valid RESP values, but safe 
>programming practice dictates that your code not 
>fail in the event of unexpected inputs.  As it 
>stands, this code would throw a runtime error 
>because hitObject would not be assigned before 
>it reaches the hitObject.BackColor 
>statement.  With that in mind, your code might work out to something like
>
>Â  Â  Dim theState As SlideState
>Â  Â  Dim hitObject As SlideText
>
>Â  Â  Set theState = ResponseSlide.States(ResponseSlide.ActiveState)
>Â  Â  Select Case ResponseSlide.RESP
>Â  Â  Case "2"
>Â  Â  Â  Â  Set hitObject = theState.Objects("Text1")
>Â  Â  Case "3"
>Â  Â  Â  Â  Set hitObject = theState.Objects("Text2")
>Â  Â  Case "4"
>Â  Â  Â  Â  Set hitObject = theState.Objects("Text3")
>Â  Â  End Select
>Â  Â  If Not(hitObject Is Nothing) Then
>Â  Â  Â  Â  hitObject.BackColor = CColor("green")
>Â  Â  Â  Â  hitObject.Draw
>    Else  ' sanity check
>Â  Â  Â  Â  ' code for invalid response here
>Â  Â  End If
>
>If you could judiciously rename your objects so 
>that they directly reflected the response value, 
>you could compact this even further, e.g.,
>
>Â  Â  Dim theState As SlideState
>Â  Â  Dim hitObject As SlideText
>
>Â  Â  Set theState = ResponseSlide.States(ResponseSlide.ActiveState)
>Â  Â  Select Case ResponseSlide.RESP
>Â  Â  Case "2", "3", "4"
>Â  Â  Â  Â  Set hitObject = theState.Objects("Text" & ResponseSlide.RESP)
>Â  Â  Â  Â  hitObject.BackColor = CColor("green")
>Â  Â  Â  Â  hitObject.Draw
>    Case Else  ' sanity check
>Â  Â  Â  Â  ' code for invalid response here
>Â  Â  End Select
>
>Just some ideas, you can take it from there.
>
>-----
>David McFarlane
>E-Prime training 
>online:Â 
><http://psychology.msu.edu/Workshops_Courses/eprime.aspx>http://psychology.msu.edu/Workshops_Courses/eprime.aspx
>Twitter:Â  @EPrimeMaster 
>(<https://twitter.com/EPrimeMaster>https://twitter.com/EPrimeMaster)
>
>/----
>Stock reminder:  1) I do not work for PST.  2) 
>You may reach PST's trained staff (and other 
>support facilities) at 
><https://support.pstnet.com>https://support.pstnet.com 
>.  3) If you do get an answer from PST staff, 
>please extend the courtesy of posting their 
>reply back here for the sake of others.
>\----
>
>
>
>At 9/4/2014 06:43 AM Thursday, Chen wrote:
>I would like to highlight an object based on the subject's response.
>
>I learned from some codes when an object was 
>selected by the subject with a mouse
>
>...unfortunately I am not smart enough to apply 
>it in when I ask my subject to give a response 
>by pressing the key "2", "3", or "4".
>
>Â Basically my subject has 3 seconds to make a choice.
>
>I would like the box surrounding the selected 
>option to change color (to green for example) 
>while the slide is still displayed, or the words 
>(in the text of the slide) change color.
>
>My code is like this:
>
>Dim theState As SlideState    '
>
>Dim hitObject As SlideText
>
>Set theState = 
>ResponseSlide.States(ResponseSlide.ActiveState)Â 
>  Â  'ResponseSlide is the name of the slide'
>
>Select Case ResponseSlide.RESP
>
>Case "2"
>
>Â  Â hitObject = theState.Objects("Text1")
>
>Case "3"
>
>Â  Â hitObject = ResponseSlide.Name("Text2")
>
>Case "4"
>
>Â  Â hitObject = ResponseSlide.Name("Text3")
>
>End Select
>
>hitObject.BackColor = CColor("green")
>
>hitObject.Draw
>
>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>the error message is like this:
>
>The object does not have an assignable default property.
>
>
>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>Hope someone can help me...I have been stuck for an entire day...;-;
>
>Thanks a lot in advance!
>
>OLI:)
>
>
>--
>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 
><mailto:e-prime%2Bunsubscribe at googlegroups.com>e-prime+unsubscribe at googlegroups.com.
>To post to this group, send email to 
><mailto:e-prime at googlegroups.com>e-prime at googlegroups.com.
>To view this discussion on the web visit 
><https://groups.google.com/d/msgid/e-prime/5408c098.1243320a.687a.0b18SMTPIN_ADDED_MISSING%40gmr-mx.google.com>https://groups.google.com/d/msgid/e-prime/5408c098.1243320a.687a.0b18SMTPIN_ADDED_MISSING%40gmr-mx.google.com.
>
>For more options, visit 
><https://groups.google.com/d/optout>https://groups.google.com/d/optout.
>
>
>
>
>--
>Yin-Hua, ChenÂ
>
>Research Center for Mind, Brain and Learning
>National Chengchi UniversityÂ
>No. 64, Sec. 2, Zhi-Nan Rd., Wen-shan District, Taipei City 11605, Taiwan
>Tel: +886 2 2234 4967

-- 
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+unsubscribe at googlegroups.com.
To post to this group, send email to e-prime at googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/e-prime/5409c1bc.4946320a.155b.0890SMTPIN_ADDED_MISSING%40gmr-mx.google.com.
For more options, visit https://groups.google.com/d/optout.



More information about the Eprime mailing list