|
March
2002 - Volume 1, Issue 2
The
Typing Speed Test program
The Typing Speed
Test program presented in this Programmer's Corner, will assist
users to increase their speed in typing. When the user clicks on
the Start button, letters will scroll down randomly in the window
of the application. The user has to make sure that he has typed
the right letter before the scrolling letter disappears. When the
user is done, he/she has to click on the Stop button. And finally,
click the Result button to display the score.
To develop the
application Start with the interface
-Add a picture box to the form, make the size bigger but don't entirely
hide the form, it will be referred as picture1.
-Add a label box referred as label1.
-Add another label box, referred as label2 for displaying the result.
-Add another label box for the first label.
-Add a horizontal scroll bar, referred as hscroll1.
-Add four command buttons. Their names will be command1, command2,
command3 & command4. And set their style property to 1-Graphical
in the properties window.
-Add two timer controls referred as Timer1 & Timer2.
Put the Controls in the right place , same position as in the above
picture.
Then write the following code in the code window (Visual Basic 6).
Option Explicit
Dim t As Integer
Dim countright As Integer
Dim Countletter As Integer
Private Sub
Command1_Click()
Timer1.Enabled = True
t = HScroll1.Value
HScroll1.Enabled = True
Label5.Visible = False
Label1.Visible = True
countright = 0
Countletter = 0
Label1.Top = Picture1.Top + Picture1.Height + 50
Timer1_Timer
Command2.Enabled = True
Command3.Enabled = False
End Sub
Private Sub
Command1_KeyPress(KeyAscii As Integer)
Picture1_KeyPress (KeyAscii)
End Sub
Private Sub
Command1_MouseMove(Button As Integer, Shift As Integer, X As Single,
Y As Single)
If Command1.Enabled = True Then
Command1.BackColor = RGB(0, 0, 256)
End If
End Sub
Private Sub
Command2_Click()
Timer1.Enabled = False
Command3.Enabled = True
Command2.Enabled = False
End Sub
Private Sub
Command2_MouseMove(Button As Integer, Shift As Integer, X As Single,
Y As Single)
If Command2.Enabled = True Then
Command2.BackColor = RGB(0, 0, 256)
End If
End Sub
Private Sub
Command3_Click()
Dim accuracy As Integer
Label2.Visible = True
Timer2.Interval = 5000
If Countletter <> 0 Then
accuracy = (100 * countright) / Countletter
End If
Label2.Caption = Countletter & " Characters were Generated
out of which " & countright & " characters were
typed right . That is " & accuracy & " % Accuracy"
Command1.Enabled = True
End Sub
Private Sub
Command3_MouseMove(Button As Integer, Shift As Integer, X As Single,
Y As Single)
If Command3.Enabled = True Then
Command3.BackColor = RGB(0, 10, 256)
End If
End Sub
Private Sub
Command4_Click()
Unload Me
End Sub
Private Sub
Command4_MouseMove(Button As Integer, Shift As Integer, X As Single,
Y As Single)
If Command4.Enabled = True Then
Command4.BackColor = RGB(0, 0, 256)
End If
End Sub
Private Sub
Form_Load()
Form1.BorderStyle = 4
Form1.Caption = "Typing Speed Test"
Form1.Picture = LoadPicture("C:\program Files\Microsoft Office\templates\1033\Column
with Contents_image001.jpg", vbLPCustom, , Form1.Top, Form1.Width)
Picture1.Picture = LoadPicture("C:\program Files\Microsoft
Office\templates\1033
\Column with Contents_image001.jpg", vbLPCustom)
Picture1.ForeColor
= vbWhite
HScroll1.Max = 400
HScroll1.Min = 10
HScroll1.Enabled = False
HScroll1.Value = 82
Label1.Appearance = 1 'drop down letters label box
Label1.BackStyle = 0
Label1.BackColor = vbBlack
Label1.ForeColor = vbWhite
Label1.FontSize = 16
Label1.Visible = False
Label1.BackStyle = 0
Label1.fontbold=True
Label2.Visible = False ' result display label box
Label2.FontSize = 16
Label2.BackColor = RGB(0, 80, 200)
Label2.ForeColor = vbWhite
Label3.Caption = "Fast"
Label3.ForeColor = RGB(256, 150, 150)
Label3.FontSize = 16
Label3.BorderStyle = 0
Label3.BackStyle = 0
Label4.Caption = "Slow"
Label4.ForeColor = RGB(256, 150, 150)
Label4.FontSize = 16
Label4.BorderStyle = 0
Label4.BackStyle = 0
Label5.Fontbold=True
Label5.Caption = " Typing Speed Test" & vbCrLf &
" Click Start To Begin!" & vbCrLf & vbcrlf &
" Developed By" & vbCrLf & " ICT Focus"
Label5.ForeColor = vbWhite
Label5.FontSize = 15
Command1.Caption
= "&Start"
Command2.Caption = "St&op"
Command3.Caption = "&Result"
Command4.Caption = "E&xit"
Command1.FontSize = 16
Command2.FontSize = 16
Command3.FontSize = 16
Command4.FontSize = 16
Command1.BackColor = RGB(0, 0, 160)
Command2.BackColor = RGB(0, 0, 160)
Command3.BackColor = RGB(0, 0, 160)
Command4.BackColor = RGB(0, 0, 160)
Command2.Enabled = False
Command3.Enabled = False
End Sub
Private Sub
Form_MouseMove(Button As Integer, Shift As Integer, X As Single,
Y As Single)
If Command1.Enabled = True Then
Command1.BackColor = RGB(0, 0, 160)
End If
If Command2.Enabled = True Then
Command2.BackColor = RGB(0, 0, 160)
End If
If Command3.Enabled = True Then
Command3.BackColor = RGB(0, 0, 160)
End If
If Command4.Enabled = True Then
Command4.BackColor = RGB(0, 0, 160)
End If
End Sub
Private Sub
HScroll1_Change()
t = HScroll1.Value
End Sub
Private Sub Timer1_Timer()
Dim x As Integer
Timer1.Interval = t
If Label1.Top >= (Picture1.Top+Picture1.Height - 50) Then
Label1.Top = 120
Label1.Left = (Picture1.Left+Rnd()* (Picture1.Width - 50))
Randomize
Label1.Left = Int(Rnd*5+1)*1000
Do
x = Rnd() *122
Loop While (x < 65 Or (x > 90 And x < 97))
Label1.Caption = Chr(x)
Countletter=Countletter + 1
Else
Label1.Top=Label1.Top + 200
End If
End Sub
Private Sub
Timer2_Timer()
Label2.Visible = False
End Sub
Private Sub
HScroll1_KeyPress(KeyAscii As Integer)
Picture1_KeyPress (KeyAscii)
End Sub
Private Sub
Picture1_KeyPress(KeyAscii As Integer)
Dim randomnumber As Integer
If (Label1.Caption <> "") Then
If KeyAscii = Asc(Label1.Caption) Then
countright = countright + 1
Label1.Top = Picture1.Top + Picture1.Height
Timer1_Timer
End If
End If
End Sub
|