怎么用VB编制打字练习程序?

怎么用VB编制打字练习程序?,第1张

建立一个随机库a="AB。CD...",然后产生50以内的随机数,从1循环到随机数,用mid循环从字库里截取一个字符。开始计时

键入框每输入一个字符change事件来判断是否和产生框字符是否一样多,如果一样多停止计时。然后又循环加mid进行对比,一样的个数/总数,得出准确率

添加控件.

command1 frame1 (label1……label6 timer1 timer2)

'窗体代码,测试好的,大概就是这样 稍微改下就可以实现你所说的功能

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) '/ 设定Label2随机显示的字母

speed = Int(Rnd * 100 + 100) '/ 设定Label2随机显示字母的速度

Label6.Left = Int(Rnd * Frame1.Width) ' / 设定Label2代表字母出现的左边位置

Label6.Top = Frame1.Top ' / 设定Label2代表字母出现的顶部位置

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


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11188876.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-14
下一篇 2023-05-14

发表评论

登录后才能评论

评论列表(0条)

保存