?
Solved

Visual Basic Reaction Test

Posted on 2003-02-20
9
Medium Priority
?
929 Views
Last Modified: 2013-12-04
Hi,
 Although I have done programming in vusual basic im stuck on how to make a reactin test. All I want it to have sonthing happen I.e the form chage colour and the user will click when it changes then display there reaction time.

Can anyone help?????

Also I want a reaction test to display two objects one on the left and one on the right when the caption pops up "right" they will click right then do the the same think get there reaction time

Thanks Gary Bates
0
Comment
Question by:GaryBates
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 

Expert Comment

by:HanrahaN
ID: 7990624
im dont really have much time today figure it all out but i thought maybe this might help anyways it would be basically the same for the second question also. its in seconds not milliseconds though. dont know if this helps but you can try it anyways.

Private StartTime As Date, EndTime As Date, ReactionTime As Long

Private Sub Command1_Click()
Timer1.Enabled = True
Command1.Visible = False
End Sub

Private Sub Form_Click()
EndTime = Now
Let Label2.Caption = "End Time = " & EndTime
ReactionTime = DateDiff("s", StartTime, EndTime)
MsgBox "Your reaction time was " & ReactionTime & " seconds."
End Sub

Private Sub Timer1_Timer()
Form1.BackColor = vbRed
StartTime = Now
Timer1.Enabled = False
Let Label1.Caption = "Start Time = " & StartTime
End Sub
0
 
LVL 16

Expert Comment

by:twalgrave
ID: 7991344
Instead of using the timer control, you can use the timer function

For example:

lStartTime = timer

private sub form_Click()

end sub
0
 
LVL 16

Expert Comment

by:twalgrave
ID: 7991348
Didn't finish before sending
Instead of using the timer control, you can use the timer function

For example:

'In your code where you start the color change.
lStartTime = timer

private sub form_Click()
   lEndTime = timer
   msgbox "Millisends of reaction:" & lEndTime-lStartTime

end sub
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:GaryBates
ID: 8004609
could you give me more information on the timer function

question has incresed to 400 pts
0
 
LVL 16

Expert Comment

by:twalgrave
ID: 8004783
The timer function returns the number of milliseconds since midnight. Here's the help file information from VB:
Timer Function
     

Returns a Single representing the number of seconds elapsed since midnight.

Syntax

Timer

Remarks

In Microsoft Windows the Timer function returns fractional portions of a second.


It is important that if you will have the computer on past midnight, you put those types of checks into place.

I hope this is what you were looking for, if not, just holler
0
 

Accepted Solution

by:
lucasneessen earned 600 total points
ID: 8004891
Wzzp,

Basically I use 2 timers in this example 1 is the timer function the other is the timer object. The Timer object does an event as set in the timer.interval. So timer1.interval = 1 means that it wil do an event after 1 second. The timer function is different This is a running timer like a stopwatch. When you program f = timer than f wil have the value of the timer at that time. For making a reaction test you can do this at the moment that the background changes and at the moment that the user clicks. The difference between the two will be the reaction time.

Here is an exemple of a reaction test. Just open a new form and add a 2 command buttons, a timer and a listbox.

'Declaires a variable to hold the moment of backgroundchange
Dim BackgroundChange As Double
'Declaires a variable to hold the click moment
Dim ClickMoment As Double

Private Sub Command1_Click()
'When button clicked

'if the timer is not off then ...
If Timer1.Interval <> 0 Then
'it sets the button on not being able to be pressed
Command1.Enabled = False
'captures the click moment
ClickMoment = Timer
'calculates the reaction time
List1.AddItem ClickMoment - BackgroundChange

'if the timer is off then ...
Else
'Choose a random reaction time
Randomize Timer
b = Int(Rnd * 8)
'sets the timer to do an event after the time has elapsed
Timer1.Interval = b * 1000
'clears the list of reaction times
List1.Clear
'changes the text of the button
Command1.Caption = "Press on color change"
Command1.Enabled = False
'makes the stop button visible
Command2.Enabled = True
End If

End Sub

Private Sub Command2_Click()
'should stop the timer but doesn't really work to well
Timer1.Interval = 0
Command1.Enabled = True
Command1.Caption = "Start test"

End Sub

Private Sub Form_Load()
'sets the text of both buttons
Command1.Caption = "Start test"
Command2.Caption = "Stop"
End Sub

Private Sub Timer1_Timer()
'when timer chooses moment to change than ...

'makes the button able to be pressed
Command1.Enabled = True

'picks a random backgroundcolor and reaction time for next press
Randomize Timer
a = Int(Rnd * 15)
b = Int(Rnd * 8)

'changes the background color and resets the timer
Form1.BackColor = QBColor(a)
Timer1.Interval = b * 1000
' Set variable to store reaction time.
BackgroundChange = Timer
End Sub
0
 
LVL 14

Assisted Solution

by:CyrexCore2k
CyrexCore2k earned 600 total points
ID: 8009807
tart a new project and put two timers and a command button on the form. disable both timers and set the interval to 1

- Code -
Dim tmp As Long
Dim StartTime As String
Private Sub Command1_Click()
If Not Timer2.Enabled Then
    MsgBox "When the form turns green hit the button."
    Randomize
    tmp = Rnd * 500
    tmp = tmp + 500
    Timer1.Enabled = True
    Command1.Caption = "Click when the form turns green"
Else
    If Me.BackColor <> vbGreen Then
        MsgBox "Hah! You clicked too soon!"
    Else
        MsgBox "Your reaction time was " & StartTime & " milliseconds."
    End If
    Timer2.Enabled = False
    Command1.Caption = "Test your reactions"
    Me.BackColor = &H8000000F
End If
End Sub

Private Sub Timer1_Timer()
tmp = tmp - 1
If tmp = 0 Then
    Me.BackColor = vbGreen
    StartTime = 0
    Timer1.Enabled = False
    Timer2.Enabled = True
End If
End Sub

Private Sub Timer2_Timer()
    StartTime = StartTime + 1
End Sub
- End Code -

Unfortunately Visual Basic is a poor timekeeper so you may notice a descrepancy with the result time. It changes from computer to computer but with some slight adjustments you should be able to make a more accurate result.

Spencer Ruport
0
 
LVL 14

Expert Comment

by:CyrexCore2k
ID: 8010335
tart a new project and put two timers and a command button on the form. disable both timers and set the interval to 1

- Code -
Dim tmp As Long
Dim StartTime As String
Private Sub Command1_Click()
If Not Timer2.Enabled Then
    MsgBox "When the form turns green hit the button."
    Randomize
    tmp = Rnd * 500
    tmp = tmp + 500
    Timer1.Enabled = True
    Command1.Caption = "Click when the form turns green"
Else
    If Me.BackColor <> vbGreen Then
        MsgBox "Hah! You clicked too soon!"
    Else
        MsgBox "Your reaction time was " & StartTime & " milliseconds."
    End If
    Timer2.Enabled = False
    Command1.Caption = "Test your reactions"
    Me.BackColor = &H8000000F
End If
End Sub

Private Sub Timer1_Timer()
tmp = tmp - 1
If tmp = 0 Then
    Me.BackColor = vbGreen
    StartTime = 0
    Timer1.Enabled = False
    Timer2.Enabled = True
End If
End Sub

Private Sub Timer2_Timer()
    StartTime = StartTime + 1
End Sub
- End Code -

Unfortunately Visual Basic is a poor timekeeper so you may notice a descrepancy with the result time. It changes from computer to computer but with some slight adjustments you should be able to make a more accurate result.

Spencer Ruport
0
 
LVL 3

Expert Comment

by:FaithRaven
ID: 9308025
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Split points to lucasneessen & CyrexCore2k
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

FaithRaven
EE Cleanup Volunteer
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question