VB打字程序

来源:互联网 发布:淘宝哪种推广方法最好 编辑:程序博客网 时间:2024/05/16 15:03

Option Explicit
Dim score As Integer
Dim speed As Integer

Sub init()
Label1.Caption = Chr(Int(Rnd * 25) + 65) '大写英文字母
speed = Int(Rnd * 50 + 50) '速度随机
Label1.Left = Int(Rnd * Frame1.Width) '左侧位置随机
Label1.Top = Frame1.Top  'top,left属性为器件顶端,左侧和容器边缘的距离
End Sub

Sub init1()
Label6.Caption = Chr(Int(Rnd * 25) + 97) 'chr转为对应的asc码
speed = Int(Rnd * 50 + 50)
Label6.Left = Int(Rnd * Frame1.Width)
Label6.Top = Frame1.Top
End Sub

Private Sub Command1_Click()
init
Timer1.Enabled = True
Timer2.Enabled = True
Command1.Visible = False
Label5.Caption = 20
Label3.Caption = 0
End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
If Chr(KeyAscii) = Label1.Caption Then
init
score = score + 1
Label3.Caption = score
End If
If Chr(KeyAscii) = Label6.Caption Then
init1
score = score + 1
Label3.Caption = score
End If
End Sub

Private Sub Form_Load()
Randomize
Timer1.Enabled = False
Timer2.Enabled = False
End Sub

Private Sub Timer1_Timer() '设置为100毫秒
Label1.Top = Label1.Top + speed
If Label1.Top > Frame1.Height Then
init
End If
Label6.Top = Label6.Top + speed
If Label6.Top > Frame1.Height Then
init1
End If
End Sub

Private Sub Timer2_Timer()
Label5.Caption = Val(Label5.Caption) - 1
If Val(Label5.Caption) <= 0 Then
Timer1.Enabled = False
Label1.Caption = ""
Label6.Caption = ""
Select Case score
Case Is <= 8
MsgBox vbCrLf + "别放弃,再来一次!", , "结果" 'vbcr是回车,本行开头,vblf是换行,跳到下一行,vbcrlf是回车换行,到下一行开头
Case Is < 12
MsgBox vbCrLf + "成绩不错,加油!", , "结果"
Case Is < 15
MsgBox vbCrLf + "再努力做的更好一些!", , "结果"
Case Is > 18
MsgBox vbCrLf + "好厉害!最高分呀!", , "结果"
End Select
Command1.Visible = True
Label3.Caption = 0
Label5.Caption = 20
score = 0
Timer1.Enabled = False
Timer2.Enabled = False
End If
End Sub

原创粉丝点击