If LenB(Text1(Index).Text) = LenB(Label1(Index).Caption) Then
If Index = rowcount Then
Timer1.Enabled = False
mode = ""
Dim i, j, rightchar As Integer
rightchar = 0
''统计每一行打字的正确字数
For i = 1 To rowcount
For j = 1 To Len(Label1(i).Caption)
If Mid(Text1(i).Text, j, 1) = Mid(Label1(i).Caption, j, 1) Then rightchar = rightchar + 1
Next
Next
If MsgBox("finish task!Correct Percent:" & Int((rightchar / totalchar) * 100) & "%" + vbCrLf + vbCrLf + "Do you want to save this practice result?", vbYesNo + vbInformation, "Hint") = vbYes Then
''将打字速度结果存入文本文件中
Open App.Path + "\count.txt" For Append As #1
If playsec = 0 Then
Print #1, 0
Else
Print #1, CStr(totalchar / playsec)
End If
Close #1
End If
''计时清0
playsec = 0
Else
Index = Index + 1
Text1(Index).SetFocus
End If
End If
End Sub
''------------------------------------------
Private Sub Text1_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
''在打字输入框中屏蔽掉方向键和删除键等,以避免玩家误操作
If KeyCode = vbKeyLeft Then KeyCode = 0
If KeyCode = vbKeyRight Then KeyCode = 0
If KeyCode = vbKeyUp Then KeyCode = 0
If KeyCode = vbKeyDown Then KeyCode = 0
If KeyCode = vbKeyDelete Then KeyCode = 0
If KeyCode = vbKeyHome Then KeyCode = 0
If KeyCode = vbKeyEnd Then KeyCode = 0
End Sub
''-------------------------------------------
Private Sub Text1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
''如果用鼠标点击输入框,则作为作弊行为,重新开始练习
MsgBox "Don''t cheat youself,Please studying carefully!" + vbCrLf + vbCrLf + "[Suggestion : This Way is to advantage you]", vbOKOnly + vbInformation, "Warning"
Call mnuRestart_Click
End Sub
''-------------------------------------------
Private Sub Timer1_Timer()
''计算当前练习所耗时间,以秒为单位
playsec = playsec + 1
StatusBar1.Panels(2).Text = "Seconds Used : " & playsec & "(S)"
End Sub
至此,你就拥有了一个属于自己的打字小软件了。按F5运行它,效果还不错吧,有兴趣的朋友还可以加上一些特殊功能,比如背景音乐,字体颜色或者游戏功能。
(备注:本
程序在VB6.0+WIN2000下调试通过)