Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1001
  • Last Modified:

Visual Basic Reaction Test

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
GaryBates
Asked:
GaryBates
2 Solutions
 
HanrahaNCommented:
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
 
twalgraveCommented:
Instead of using the timer control, you can use the timer function

For example:

lStartTime = timer

private sub form_Click()

end sub
0
 
twalgraveCommented:
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
Technology Partners: 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!

 
GaryBatesAuthor Commented:
could you give me more information on the timer function

question has incresed to 400 pts
0
 
twalgraveCommented:
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
 
lucasneessenCommented:
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
 
CyrexCore2kCommented:
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
 
CyrexCore2kCommented:
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
 
FaithRavenCommented:
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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now