本次课程设计做了一个打字测试练习,速度,时间等都搞定了,只是一个问题就是没有办法统计按键的次数和正确按键次数窗体如下:
Public t As Integer         't代表时间Public speed As Integer      '字母落下的速度的top值Private Sub Form_Load()  '主窗体t = 15                   '设置初始时间speed = 100               '设置初始速度Label1.Visible = False '最初“剩余时间”不显示Label3.Top = 0      '所有label的初始位置确定
Label4.Top = 800
Label5.Top = 240
Label6.Top = 120
Label7.Top = 450
Label8.Top = 200
Label9.Top = 600Timer1.Enabled = False
Timer2.Enabled = FalseEnd SubPrivate Sub Command1_KeyPress(KeyAscii As Integer)    '键盘触发事件,按下键盘,label的caption消失
If Asc(Label3.Caption) = KeyAscii ThenLabel3.Caption = " "
Label3.Top = Int(Rnd * 800)
End IfIf Asc(Label4.Caption) = KeyAscii ThenLabel4.Caption = " "
Label4.Top = Int(Rnd * 800)
End If
If Asc(Label5.Caption) = KeyAscii ThenLabel5.Caption = " "
Label5.Top = Int(Rnd * 800)
End IfIf Asc(Label6.Caption) = KeyAscii ThenLabel6.Caption = " "
Label6.Top = Int(Rnd * 800)
End IfIf Asc(Label7.Caption) = KeyAscii ThenLabel7.Caption = " "
Label7.Top = Int(Rnd * 800)
End IfIf Asc(Label8.Caption) = KeyAscii ThenLabel8.Caption = " "
Label8.Top = Int(Rnd * 800)
End If
If Asc(Label9.Caption) = KeyAscii ThenLabel9.Caption = " "
Label9.Top = Int(Rnd * 800)
End IfEnd SubPrivate Sub Picture2_KeyPress(KeyAscii As Integer)   '使键盘在触及到picture2时也能响应
If Asc(Label3.Caption) = KeyAscii ThenLabel3.Caption = " "
Label3.Top = Int(Rnd * 800)
End IfIf Asc(Label4.Caption) = KeyAscii ThenLabel4.Caption = " "
Label4.Top = Int(Rnd * 800)
End If
If Asc(Label5.Caption) = KeyAscii ThenLabel5.Caption = " "
Label5.Top = Int(Rnd * 800)
End IfIf Asc(Label6.Caption) = KeyAscii ThenLabel6.Caption = " "
Label6.Top = Int(Rnd * 800)
End IfIf Asc(Label7.Caption) = KeyAscii ThenLabel7.Caption = " "
Label7.Top = Int(Rnd * 800)
End IfIf Asc(Label8.Caption) = KeyAscii ThenLabel8.Caption = " "
Label8.Top = Int(Rnd * 800)
End If
If Asc(Label9.Caption) = KeyAscii ThenLabel9.Caption = " "
Label9.Top = Int(Rnd * 800)
End IfEnd SubPrivate Sub Form_KeyPress(KeyAscii As Integer)    '在form的任何地方都能触发键盘响应If Asc(Label3.Caption) = KeyAscii ThenLabel3.Caption = " "
Label3.Top = Int(Rnd * 800)
End IfIf Asc(Label4.Caption) = KeyAscii ThenLabel4.Caption = " "
Label4.Top = Int(Rnd * 800)
End If
If Asc(Label5.Caption) = KeyAscii ThenLabel5.Caption = " "
Label5.Top = Int(Rnd * 800)
End IfIf Asc(Label6.Caption) = KeyAscii ThenLabel6.Caption = " "
Label6.Top = Int(Rnd * 800)
End IfIf Asc(Label7.Caption) = KeyAscii ThenLabel7.Caption = " "
Label7.Top = Int(Rnd * 800)
End IfIf Asc(Label8.Caption) = KeyAscii ThenLabel8.Caption = " "
Label8.Top = Int(Rnd * 800)
End If
If Asc(Label9.Caption) = KeyAscii ThenLabel9.Caption = " "
Label9.Top = Int(Rnd * 800)
End If
End Sub
Private Sub Command1_Click()   '开始按钮中的“开始”
ProgressBar1.Value = Min     '当前进度条为最小值
ProgressBar1.Max = t        '进度条的最大值Randomize Label3.Caption = Chr(Int(26 * Rnd + 97))
 Label4.Caption = Chr(Int(26 * Rnd + 97))
 Label5.Caption = Chr(Int(26 * Rnd + 97))
 Label6.Caption = Chr(Int(26 * Rnd + 97))
 Label7.Caption = Chr(Int(26 * Rnd + 97))
 Label8.Caption = Chr(Int(26 * Rnd + 97))
 Label9.Caption = Chr(Int(26 * Rnd + 97))
 
Label1.Visible = True
Timer1.Enabled = True
Timer2.Enabled = TrueEnd Sub
Private Sub start_Click()    '菜单中的“开始”ProgressBar1.Value = Min     '当前进度条为最小值
ProgressBar1.Max = t        '进度条的最大值
Randomize Label3.Caption = Chr(Int(26 * Rnd + 97))
 Label4.Caption = Chr(Int(26 * Rnd + 97))
 Label5.Caption = Chr(Int(26 * Rnd + 97))
 Label6.Caption = Chr(Int(26 * Rnd + 97))
 Label7.Caption = Chr(Int(26 * Rnd + 97))
 Label8.Caption = Chr(Int(26 * Rnd + 97))
 Label9.Caption = Chr(Int(26 * Rnd + 97))
 
Label1.Visible = True
Timer1.Enabled = True
Timer2.Enabled = TrueEnd Sub
Private Sub reenter_Click()   '菜单中的重新登录Form1.Show
Form3.Hide
Form1.Text1.Text = ""
Form1.Text2.Text = ""End Sub
Private Sub exit_Click()   '菜单中的“退出”EndEnd Sub
Private Sub speed1_Click()  '以下三个为菜单栏中的速度设置
speed = 100
Label10.Caption = "蜗牛爬爬"
End Sub
Private Sub speed2_Click()
speed = 150
Label10.Caption = "公路赛车"
End SubPrivate Sub speed3_Click()
Label10.Caption = "极速狂飙"
speed = 200
End Sub
Private Sub sec15_Click()   '以下三个为菜单栏中的时间设置
Label11.Caption = "15秒"
t = 15
End SubPrivate Sub sec30_Click()
Label11.Caption = "30秒"
t = 30
End SubPrivate Sub sec60_Click()
Label11.Caption = "60秒"
t = 60
End SubPrivate Sub crazymode_Click()
Label10.Caption = "狂人模式"
Label11.Caption = "90秒"
speed = 300
t = 90End SubPrivate Sub Timer1_Timer()    '记时器控件,控制下方的剩余时间显示StatusBar1.Panels.Item(1) = "已出现字母:"      '状态栏显示的进度StatusBar1.Panels.Item(3) = "已按键次数:"
StatusBar1.Panels.Item(5) = "正确个数:"StatusBar1.Panels.Item(7) = "正确率:"
t = t - 1Label2.Caption = t & "秒"          '字母区下方的剩余时间显示If (t = 0) ThenLabel3.Visible = False     '时间到以后所有的label都消失不可见
Label4.Visible = False
Label5.Visible = False
Label6.Visible = False
Label7.Visible = False
Label8.Visible = False
Label9.Visible = FalseTimer1.Enabled = False
Timer2.Enabled = FalseMsgBox "对不起,您的时已经间到了!", , "Attention!"End IfProgressBar1.Value = ProgressBar1.Value + 1End SubPrivate Sub Timer2_Timer()  '控制字母落下
Label3.Top = Label3.Top + speed
If Label3.Top > 5840 Then   
   Label3.Visible = False
   Label3.Top = Int(Rnd * 800)
   Label3.Caption = Chr(Int(26 * Rnd + 97))
   Label3.Visible = True
   
   End If   
Label4.Top = Label4.Top + speed
If Label4.Top > 5840 Then   
   Label4.Visible = False
   Label4.Top = Int(Rnd * 800)
   Label4.Caption = Chr(Int(26 * Rnd + 97))
   Label4.Visible = True
   End If
   
Label5.Top = Label5.Top + speed
If Label5.Top > 5840 Then   
   Label5.Visible = False
   Label5.Top = Int(Rnd * 800)
   Label5.Caption = Chr(Int(26 * Rnd + 97))
   Label5.Visible = True
   End If
   
Label6.Top = Label6.Top + speed
If Label6.Top > 5840 Then   
   Label6.Visible = False
   Label6.Top = Int(Rnd * 800)
   Label6.Caption = Chr(Int(26 * Rnd + 97))
   Label6.Visible = True
   End If
   
Label7.Top = Label7.Top + speed
If Label7.Top > 5840 Then   
   Label7.Visible = False
   Label7.Top = Int(Rnd * 800)
   Label7.Caption = Chr(Int(26 * Rnd + 97))
   Label7.Visible = True
   End IfLabel8.Top = Label8.Top + speed
If Label8.Top > 5840 Then 
   Label8.Visible = False
   Label8.Top = Int(Rnd * 800)
   Label8.Caption = Chr(Int(26 * Rnd + 97))
   Label8.Visible = True
   End If
   
Label9.Top = Label9.Top + speed
If Label9.Top > 5840 Then  
   Label9.Visible = False
   Label9.Top = Int(Rnd * 800)
   Label9.Caption = Chr(Int(26 * Rnd + 97))
   Label9.Visible = True
   End If
   
End Sub
Private Sub about_Click()               '关于菜单
Form4.ShowEnd Sub
Private Sub help_theme_Click()          '帮助主题Form5.ShowEnd Sub此前用设过一个变量button,if keypress then button=button+1,但是在下面的状态栏中永远都显示1很郁闷,正确数也统计不出,只剩这一个问题来,恳请高手支招!