Name: Anonymous 2009-05-21 17:07
Help /prog/, why does this program keep freezing?
'Reaction.exe'
'Picture comes up once, user presses left side of keyboard (Q,A,or Z)'
'Picture comes up a second time, user presses right side of keyboard (P,L,or M)'
'A total of 10 .jpgs, pictures show up randomly, a picture will only show up twice'
'Time (in millisecods) is recorded for each attempt'
'If user presses correct key,'
'For example if user presses 2 and it is the 2nd time the picture has shown up'
'Accuracy goes up a point (maximum of 10)'
'If user presses wrong key, '
'For example if user presses 2 even though the picture has only shown up once'
'Accuracy goes down a point (minimum of 0)'
Public Class Form_Main
'Declare Globals'
Public X, I, Num, Flag, Accuracy As Integer = 0
Public Speed, Timer_Start, Timer_End As Double = 0
Public Times(20) As Double 'Holds 20 times (since each picture will pop up twice)'
'MainArray'
'value = How many images will be used (Default is 10, for 10 pictures)'
' 0 = Picture hasn't been used yet'
' 1 = Picutre has been used'
' 2 = Picture has already been used twice, and will not appear again'
Dim MainArray(10) As Integer
' Start Button click (Main Function)'
Private Sub Button_Start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Start.Click
'Images branch'
If RadioButton_Images.Checked Then
Images()
End If
'Functions'
'Images() Function'
Private Function Images() As Action
Do Until (Num = 10)
Timer_Start = 0
Timer_End = 0
Flag = 0
Timer_Delay.Enabled = False
Timer_Delay.Interval = Rand(3000, 5000) 'Random delay between 3 seconds and 5 seconds'
Timer_Delay.Enabled = True
Do While (Flag = 0)
Timer_Delay.Enabled = False
If PictureBox.Visible = False Then
DisplayImage()
Timer_Start = TimeOfDay.Millisecond
End If
Loop
CalcTime()
Loop
End Function
'Rand() Function (returns a random integer between (x,y) )'
Private Function Rand(ByVal Low As Long, ByVal High As Long) As Long
'randomize function
Randomize()
Rand = Int((High - Low + 1) * Rnd()) + Low
End Function
'DisplayImage() Function'
Private Function DisplayImage() As Action
Do Until PictureBox.Visible = True
Randomize()
X = Rand(1, 10) 'Get a random number from 1 to 10'
Select Case X
Case Is = 1
If MainArray(X) = 0 Then 'First time the picture is used'
PictureBox.ImageLocation = "C:\Reaction\Images\1.jpg"
MainArray(X) = 1
PictureBox.Visible = True
ElseIf MainArray(X) = 1 Then 'Second time the picture is up'
PictureBox.ImageLocation = "C:\Reaction\Images\1.jpg"
MainArray(X) = 2
Num = Num + 1
PictureBox.Visible = True
Else 'If MainArray(X) doesn't = 1 or 0'
End If 'Then endif and get another rand #'
Case Is = 2
If MainArray(X) = 0 Then
PictureBox.ImageLocation = "C:\Reaction\Images\2.jpg"
MainArray(X) = 1
PictureBox.Visible = True
ElseIf MainArray(X) = 1 Then
PictureBox.ImageLocation = "C:\Reaction\Images\2.jpg"
MainArray(X) = 2
Num = Num + 1
PictureBox.Visible = True
Else
End If
Case Is = 3
If MainArray(X) = 0 Then
PictureBox.ImageLocation = "C:\Reaction\Images\3.jpg"
MainArray(X) = 1
PictureBox.Visible = True
ElseIf MainArray(X) = 1 Then
PictureBox.ImageLocation = "C:\Reaction\Images\3.jpg"
MainArray(X) = 2
Num = Num + 1
PictureBox.Visible = True
Else
End If
...
End Function
Private Function CalcTime() As Action
Times(I) = Timer_Start - Timer_End
I = I + 1 'Records 20 times
End Function
Private Sub Form_Main_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
'Keypress Q, A, or Z if the picture is seen for the first time'
'Otherwise one accuracy point is deducted'
If e.KeyChar = "Q" Or "A" Or "Z" Or "q" Or "a" Or "z" Then
If PictureBox.Visible = True Then
If MainArray(X) = 1 Then
Timer_End = TimeOfDay.Millisecond
PictureBox.Image = Nothing
PictureBox.Visible = False
Accuracy = Accuracy + 1
Flag = 1
Else
Timer_End = TimeOfDay.Millisecond
PictureBox.Image = Nothing
PictureBox.Visible = False
Accuracy = Accuracy - 1
Flag = 1
End If
End If
End If
'Keypress for second occurance'
If e.KeyChar = "P" Or "L" Or "M" Or "p" Or "l" Or "m" Then
If PictureBox.Visible = True Then
If MainArray(X) = 2 Then
Timer_End = TimeOfDay.Millisecond
PictureBox.Image = Nothing
PictureBox.Visible = False
Accuracy = Accuracy + 1
Flag = 1
Else
Timer_End = TimeOfDay.Millisecond
PictureBox.Image = Nothing
PictureBox.Visible = False
Accuracy = Accuracy - 1
Flag = 1
End If
End If
End If
End Sub
End Class