Mouse Reaction Test

This program tests your ability to react with the mouse to graphical information displayed on the screen e.g. on a game. Just insert a timer control and use this code:

Option Explicit

Dim points As Integer
Dim c As Long
Dim cw As Boolean

Private Sub Form_DblClick()
Timer1.Enabled = True
Call Timer1_Timer
End Sub

Private Sub Form_Load()
Me.AutoRedraw = True
Me.FillStyle = vbSolid
Timer1.Enabled = False
Timer1.Interval = 1500
Me.Caption = "Points: " & 0
Me.Print "Double Click to begin."
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim g As Boolean
If Me.Point(x, y) = c And Not cw Then
   Select Case c
       Case Is <= vbRed
           If Button = vbLeftButton Then g = True
       Case Is <= vbGreen
           If Button = vbMiddleButton Then g = True
       Case Is <= vbBlue
           If Button = vbRightButton Then g = True
   End Select
   If g = True Then
       points = points + 3
   Else
       points = points - 2
       cw = True
   End If
End If
Me.Caption = "Points: " & points
End Sub

Private Sub Timer1_Timer()
Dim x As Single
Dim y As Single
Dim col As Single
Timer1.Interval = Timer1.Interval - 20
If Timer1.Interval = 20 Or points < 0 Then
   MsgBox "Your score is " & points & " points.", vbInformation
   Timer1.Enabled = False
   Call Form_Load
End If
Me.Cls
cw = False
Randomize: Randomize: Randomize
x = Rnd() * Me.ScaleWidth
Randomize: Randomize: Randomize
y = Rnd() * Me.ScaleHeight
Randomize: Randomize: Randomize
col = Rnd()
Select Case col
   Case Is <= 1 / 3
       c = vbRed
   Case Is <= 2 / 3
       c = vbGreen
   Case Is <= 3 / 3
       c = vbBlue
End Select
Me.FillColor = c
Me.Circle (x, y), 200, Me.FillColor
End Sub

You might also like...

Comments

Alex

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“C++: an octopus made by nailing extra legs onto a dog.” - Steve Taylor