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

David McFarlane mcfarla9 at msu.edu
Thu Sep 4 19:41:54 UTC 2014


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
Twitter:  @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 .  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 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/5408c098.1243320a.687a.0b18SMTPIN_ADDED_MISSING%40gmr-mx.google.com.
For more options, visit https://groups.google.com/d/optout.



More information about the Eprime mailing list