i have code of a reaction time test in VB6 that works fine however i need it in VB 2005... im assuming its the same as 2008?
The code isnt that big its fairly understandable however i just cant get it to work as some things in vb6 are different to 2005.
What the program does is. You click the green GO and it changes to a yellow. Then random time intervals a box will turn red and you click it as fast as you can.. then a msgbox pops up. you do this 5 times and get an average.
Things i cant work out how to fix when i convert:
Timer
Wait
DoEvents
Checkbox = 1 or 0 .. always underlined under the 1 and 0
What are the equivalent of those in the newer versions?
Thats it, image:

Public fin As Integer Sub CommandButton1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) If (Not UserForm1.CommandButton1.BackColor = &HFFFF&) Then Dim score(1 To 5) As Double UserForm1.CommandButton1.BackColor = &HFFFF& Rem: wait a random time 1-5 seconds Dim PauseTime, Start, Finish, TotalTime, butto While fin < 6 fin = fin + 1 PauseTime = Rnd * 4 + 2 ' Set duration 2 to 6 seconds Wait = Timer ' Set start time. Do While Timer < Wait + PauseTime DoEvents ' Yield to other processes. Loop butto = Int(Rnd * 4) Select Case butto Case 0 UserForm1.CommandButton6.BackColor = &HFF& Case 1 UserForm1.CommandButton3.BackColor = &HFF& Case 2 UserForm1.CommandButton4.BackColor = &HFF& Case 3 UserForm1.CommandButton5.BackColor = &HFF& Case 4 UserForm1.CommandButton5.BackColor = &HFF& End Select Start = Timer ' Set Go time. Do While UserForm1.CheckBox1 = 0 And Timer < Start + 5 DoEvents ' Yield to other processes. Loop Finish = Timer TotalTime = Finish - Start ' Calculate total time. score(fin) = TotalTime MsgBox "Try " & fin & ": You took " & TotalTime & " seconds" If (fin >= 5) Then ave = (score(1) + score(2) + score(3) + score(4) + score(5)) / 5 Comment = " Not Bad!" If ave < 0.75 Then Comment = " Pretty good!" If ave > 1# Then Comment = " Not so good, perhaps you should try again." MsgBox "Average reaction time = " & ave & " seconds. " & Comment Sheet1.Cells(10, 3) = ave End End If Rem: activate one of 4 buttons, record time UserForm1.CommandButton6.BackColor = &H8000000F UserForm1.CommandButton3.BackColor = &H8000000F UserForm1.CommandButton4.BackColor = &H8000000F UserForm1.CommandButton5.BackColor = &H8000000F UserForm1.CheckBox1 = 0 Wend UserForm1.CommandButton1.BackColor = &HFF00& End If End Sub Sub CommandButton3_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) If (UserForm1.CommandButton3.BackColor = &HFF&) Then UserForm1.CheckBox1 = 1 End Sub Sub CommandButton4_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) If (UserForm1.CommandButton4.BackColor = &HFF&) Then UserForm1.CheckBox1 = 1 End Sub Sub CommandButton5_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) If (UserForm1.CommandButton5.BackColor = &HFF&) Then UserForm1.CheckBox1 = 1 End Sub Sub CommandButton6_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) If (UserForm1.CommandButton6.BackColor = &HFF&) Then UserForm1.CheckBox1 = 1 End Sub
My 2005 Version so far not working at all:
Public Class UserForm
Public fin As Integer
Dim Comment As String
Dim ave As Integer
Sub CommandButton1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If (Not CommandButton1.BackColor = Color.Yellow) Then
Dim score(0 To 5) As Double
CommandButton1.BackColor = Color.Yellow
REM: wait a random time 1-5 seconds
Dim PauseTime, Start, Finish, TotalTime, butto
While fin < 6
fin = fin + 1
PauseTime = Rnd() * 4 + 2 ' Set duration 2 to 6 seconds
Wait = Timer ' Set start time.
Do While Timer1 < Wait + PauseTime
DoEvents() ' Yield to other processes.
Loop
butto = Int(Rnd() * 4)
Select Case butto
Case 0
CommandButton6.BackColor = Color.Red
Case 1
CommandButton3.BackColor = Color.Red
Case 2
CommandButton4.BackColor = Color.Red
Case 3
CommandButton5.BackColor = Color.Red
Case 4
CommandButton5.BackColor = Color.Red
End Select
Start = Timer1 ' Set Go time.
Do While CheckBox1 = 0 And Timer < Start + 5
DoEvents() ' Yield to other processes.
Loop
Finish = Timer
TotalTime = Finish - Start ' Calculate total time.
score(fin) = TotalTime
MsgBox("Try " & fin & ": You took " & TotalTime & " seconds")
If (fin >= 5) Then
ave = (score(1) + score(2) + score(3) + score(4) + score(5)) / 5
Comment = " Not Bad!"
If ave < 0.75 Then Comment = " Pretty good!"
If ave > 1.0# Then Comment = " Not so good, perhaps you should try again."
MsgBox("Average reaction time = " & ave & " seconds. " & Comment)
End
End If
REM: activate one of 4 buttons, record time
CommandButton6.BackColor = Color.White
CommandButton3.BackColor = Color.White
CommandButton4.BackColor = Color.White
CommandButton5.BackColor = Color.White
CheckBox1 = 0
End While
CommandButton1.BackColor = Color.White
End If
End Sub
Sub CommandButton3_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If (CommandButton3.BackColor = Color.Red) Then CheckBox1 = 1
End Sub
Sub CommandButton4_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If (CommandButton4.BackColor = Color.Red) Then CheckBox1 = 1
End Sub
Sub CommandButton5_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If (CommandButton5.BackColor = Color.Red) Then CheckBox1 = 1
End Sub
Sub CommandButton6_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If (CommandButton6.BackColor = Color.Red) Then CheckBox1 = 1
End Sub
End Class

Add Reply




MultiQuote


| 


