用VB做打字练习应用程序
OptionExplicitDimscoreAsIntegerDimspeedAsIntegerDimtypetimeAsString'初始化字符1Subinnt1()'...
Option Explicit
Dim score As Integer
Dim speed As Integer
Dim typetime As String
'初始化字符1
Sub innt1()
'产生随机大写字母、数字及其他符号
zi1.Caption = Chr(Int(Rnd * 43 + 48))
'起初位置
zi1.Left = Int(Rnd * (mm1.Width - zi1.Width))
zi1.Top = mm1.Top - zi1.Height
End Sub
'初始化字符2
Sub innt2()
'产生随机小写字母
zi2.Caption = Chr(Int(Rnd * 26) + 97)
'起初位置
zi2.Left = Int(Rnd * (mm1.Width - zi2.Width))
zi2.Top = mm1.Top - zi2.Height
End Sub
'开始
Private Sub Command1_Click()
'输入时间
typetime = InputBox("请输入打字时间(单位为秒):", "设置时间")
If IsNumeric(typetime) Then
Label5.Caption = typetime
Else
Exit Sub
End If
'调用子过程
innt1
innt2
'设置默认的下落速度
HScroll1.Value = 50
'开始下落
Timer1.Enabled = True
Timer2.Enabled = True
Command1.Enabled = False
Label3.Caption = 0
'设置时间为2分钟
End Sub
'打字
Private Sub HScroll1_KeyPress(KeyAscii As Integer)
'若打中字符1
If Chr(KeyAscii) = zi1.Caption Then
'重新初始化
innt1
'分数累加
score = score + 1
'显示分数
Label3.Caption = score
End If
'若打中字符2
If Chr(KeyAscii) = zi2.Caption Then
innt2
score = score + 1
Label3.Caption = score
End If
End Sub
'初始化设置
Private Sub Form_Load()
Randomize
Timer1.Enabled = False
Timer2.Enabled = False
zi1.AutoSize = True
zi2.AutoSize = True
HScroll1.Max = 300
HScroll1.Min = 10
End Sub
'改变速度
Private Sub HScroll1_Change()
speed = HScroll1.Value
End Sub
'字符下落
Private Sub Timer1_Timer()
'字符1下落
zi1.Top = zi1.Top + speed
If zi1.Top > mm1.Height Then
innt1
End If
'字符2下落
zi2.Top = zi2.Top + speed
If zi2.Top > mm1.Height Then
innt2
End If
End Sub
'控制打字时间
Private Sub Timer2_Timer()
'减时
Label5.Caption = Val(Label5.Caption) - 1
'若时间到
If Val(Label5.Caption) <= 0 Then
'停止字符下落
Timer1.Enabled = False
zi1.Caption = ""
zi2.Caption = ""
'分析分数
Select Case score
Case Is < 60
MsgBox vbCrLf + "你真菜!努力吧!"
Case Is >= 60
MsgBox vbCrLf + "恩~!还可以有进步!"
Case Is >= 100
MsgBox vbCrLf + "哈```满分!"
Case Is > 150
MsgBox vbCrLf + "好厉害啊`!"
End Select
Command1.Enabled = True
Timer1.Enabled = False
Timer2.Enabled = False
End If
End Sub
程序运行后,系统说zi1和zi2未定义,我实在是看不出来了,请哪个高人指点一下 展开
Dim score As Integer
Dim speed As Integer
Dim typetime As String
'初始化字符1
Sub innt1()
'产生随机大写字母、数字及其他符号
zi1.Caption = Chr(Int(Rnd * 43 + 48))
'起初位置
zi1.Left = Int(Rnd * (mm1.Width - zi1.Width))
zi1.Top = mm1.Top - zi1.Height
End Sub
'初始化字符2
Sub innt2()
'产生随机小写字母
zi2.Caption = Chr(Int(Rnd * 26) + 97)
'起初位置
zi2.Left = Int(Rnd * (mm1.Width - zi2.Width))
zi2.Top = mm1.Top - zi2.Height
End Sub
'开始
Private Sub Command1_Click()
'输入时间
typetime = InputBox("请输入打字时间(单位为秒):", "设置时间")
If IsNumeric(typetime) Then
Label5.Caption = typetime
Else
Exit Sub
End If
'调用子过程
innt1
innt2
'设置默认的下落速度
HScroll1.Value = 50
'开始下落
Timer1.Enabled = True
Timer2.Enabled = True
Command1.Enabled = False
Label3.Caption = 0
'设置时间为2分钟
End Sub
'打字
Private Sub HScroll1_KeyPress(KeyAscii As Integer)
'若打中字符1
If Chr(KeyAscii) = zi1.Caption Then
'重新初始化
innt1
'分数累加
score = score + 1
'显示分数
Label3.Caption = score
End If
'若打中字符2
If Chr(KeyAscii) = zi2.Caption Then
innt2
score = score + 1
Label3.Caption = score
End If
End Sub
'初始化设置
Private Sub Form_Load()
Randomize
Timer1.Enabled = False
Timer2.Enabled = False
zi1.AutoSize = True
zi2.AutoSize = True
HScroll1.Max = 300
HScroll1.Min = 10
End Sub
'改变速度
Private Sub HScroll1_Change()
speed = HScroll1.Value
End Sub
'字符下落
Private Sub Timer1_Timer()
'字符1下落
zi1.Top = zi1.Top + speed
If zi1.Top > mm1.Height Then
innt1
End If
'字符2下落
zi2.Top = zi2.Top + speed
If zi2.Top > mm1.Height Then
innt2
End If
End Sub
'控制打字时间
Private Sub Timer2_Timer()
'减时
Label5.Caption = Val(Label5.Caption) - 1
'若时间到
If Val(Label5.Caption) <= 0 Then
'停止字符下落
Timer1.Enabled = False
zi1.Caption = ""
zi2.Caption = ""
'分析分数
Select Case score
Case Is < 60
MsgBox vbCrLf + "你真菜!努力吧!"
Case Is >= 60
MsgBox vbCrLf + "恩~!还可以有进步!"
Case Is >= 100
MsgBox vbCrLf + "哈```满分!"
Case Is > 150
MsgBox vbCrLf + "好厉害啊`!"
End Select
Command1.Enabled = True
Timer1.Enabled = False
Timer2.Enabled = False
End If
End Sub
程序运行后,系统说zi1和zi2未定义,我实在是看不出来了,请哪个高人指点一下 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询