📄 tt.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "打字练习"
ClientHeight = 4050
ClientLeft = 60
ClientTop = 345
ClientWidth = 6765
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 4050
ScaleWidth = 6765
StartUpPosition = 3 '窗口缺省
Begin VB.Timer Timer2
Interval = 1000
Left = 5640
Top = 1800
End
Begin VB.Timer Timer1
Interval = 100
Left = 5640
Top = 1200
End
Begin VB.CommandButton Command1
Caption = "开始"
Height = 495
Left = 5520
TabIndex = 6
Top = 3240
Width = 975
End
Begin VB.Frame Frame1
BorderStyle = 0 'None
Height = 3855
Left = 0
TabIndex = 0
Top = 0
Width = 4815
Begin VB.Label Label6
Caption = "Label6"
Height = 495
Left = 3000
TabIndex = 7
Top = 1800
Width = 855
End
Begin VB.Label Label1
Caption = "Label1"
Height = 375
Left = 1080
TabIndex = 1
Top = 240
Width = 735
End
End
Begin VB.Label Label5
BorderStyle = 1 'Fixed Single
Caption = "Label5"
Height = 255
Left = 5760
TabIndex = 5
Top = 600
Width = 855
End
Begin VB.Label Label4
BorderStyle = 1 'Fixed Single
Caption = "Label4"
Height = 255
Left = 5760
TabIndex = 4
Top = 240
Width = 855
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "剩余:"
Height = 180
Left = 5160
TabIndex = 3
Top = 600
Width = 540
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "得分:"
Height = 180
Left = 5160
TabIndex = 2
Top = 240
Width = 540
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim score As Integer '定义变量
Dim speed As Integer '定义变量
Sub init()
Label1.Caption = Chr(Int(Rnd * 26) + 49) '设定Label1随机显示的字母
speed = Int(Rnd * 100 + 100) '设定Label1随机显示字母的速度
Label1.Left = Int(Rnd * Frame1.Width) '设定Label1代表字母出现的左边位置
Label1.Top = Frame1.Top '设定Label1代表字母出现的顶部位置
End Sub
Sub init1()
Label6.Caption = Chr(Int(Rnd * 26) + 97) '设定Label6随机显示的字母
speed = Int(Rnd * 100 + 100) '设定Label6随机显示字母的速度
Label6.Left = Int(Rnd * Frame1.Width) '设定Label6代表字母出现的左边位置
Label6.Top = Frame1.Top '设定Label6代表字母出现的顶部位置
End Sub
Private Sub Command1_Click()
init '调用init子程序
Timer1.Enabled = True '激活Time1控件
Timer2.Enabled = True '激活Time2控件
Command1.Visible = False '禁止命令按钮
Label5.Caption = 200 '显示剩余数
Label4.Caption = 0 '显示得分情况
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
If Chr(KeyAscii) = Label1.Caption Then '校验键盘输入字符和Label1显示的字符
init
score = score + 1 ' 得分加1
Label4.Caption = score
End If
If Chr(KeyAscii) = Label6.Caption Then '校验键盘输入字符和Label2显示的字符
init1
score = score + 1
Label4.Caption = score 'Label4控件显示得分情况
End If
End Sub
Private Sub Form_Load()
Randomize
Timer1.Enabled = False 'Time1控件失效
Timer2.Enabled = False 'Time2控件失效
End Sub
Private Sub Timer1_Timer()
Label1.Top = Label1.Top + speed
If Label1.Top > Frame1.Height Then '第一个字母超出屏幕范围的时候调用init子程序重新出现一个字母
init
End If
Label6.Top = Label6.Top + speed
If Label6.Top > Frame1.Height Then '第二个字母超出屏幕范围的时候调用init1子程序重新出现一个字母
init1
End If
End Sub
Private Sub Timer2_Timer()
Label5.Caption = Val(Label5.Caption) - 1 '扣除剩余个数中的一个
If Val(Label5.Caption) <= 0 Then
Timer1.Enabled = False ' 剩余个数小于等于0的时候结束练习
Label1.Caption = "" '不显示字母
Label6.Caption = ""
Select Case score
Case Is <= 80
MsgBox vbCrLf + "别放弃,再来一次!" '显示信息框
Case Is < 120
MsgBox vbCrLf + "成绩不错,加油!"
Case Is < 150
MsgBox vbCrLf + "再努力做的更好一些!"
Case Is > 180
MsgBox vbCrLf + "好厉害!最高分呀!"
End Select
Command1.Visible = True
Label4.Caption = 0
Label5.Caption = 200
Timer1.Enabled = False
Timer2.Enabled = False
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -