
VB疑难编码,软件visual studio
打字训练程序编写程序,随机生成30个由小写字母组成的字符串,可实现训练时实际“用时”、“准确率”的统计功能。...
打字训练程序编写程序,随机生成30个由小写字母组成的字符串,可实现训练时实际“用时”、“准确率”的统计功能。
展开
2个回答
展开全部
'添加text1,2,3共3个,一个Timer1,一个Command1,在text2中输入,回车后出结果
Private Sub Command1_Click()
Dim s As String
Dim n As Integer, i As Integer
Randomize Time()
For n = 0 To 29
i = Int(Rnd * (122 - 97 + 1) + 97)
s = s & Chr(i)
Next
Text1.Text = s
Text2.Text = ""
Text3.Text = "0"
Text2.SetFocus
Timer1.Interval = 1000
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
Dim s1 As String, s2 As String, tmp1 As String, tmp2 As String
Dim i As Integer, k As Integer
If KeyAscii = 13 Then
Timer1.Interval = 0
s1 = Trim(Text1.Text)
If Len(Text2.Text) < 30 Then
s2 = Text2.Text & Space(30 - Len(Text2.Text))
Else
s2 = Mid(Text2.Text, 1, 30)
End If
k = 0
For i = 1 To Len(s2)
tmp1 = Mid(s1, i, 1)
tmp2 = Mid(s2, i, 1)
If tmp1 = tmp2 Then
k = k + 1
End If
Next
MsgBox k & "个 " & Format(k * 100 / 30, "0.00") & "%"
End If
End Sub
Private Sub Timer1_Timer()
Text3.Text = Val(Text3.Text) + 1
End Sub
Private Sub Command1_Click()
Dim s As String
Dim n As Integer, i As Integer
Randomize Time()
For n = 0 To 29
i = Int(Rnd * (122 - 97 + 1) + 97)
s = s & Chr(i)
Next
Text1.Text = s
Text2.Text = ""
Text3.Text = "0"
Text2.SetFocus
Timer1.Interval = 1000
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
Dim s1 As String, s2 As String, tmp1 As String, tmp2 As String
Dim i As Integer, k As Integer
If KeyAscii = 13 Then
Timer1.Interval = 0
s1 = Trim(Text1.Text)
If Len(Text2.Text) < 30 Then
s2 = Text2.Text & Space(30 - Len(Text2.Text))
Else
s2 = Mid(Text2.Text, 1, 30)
End If
k = 0
For i = 1 To Len(s2)
tmp1 = Mid(s1, i, 1)
tmp2 = Mid(s2, i, 1)
If tmp1 = tmp2 Then
k = k + 1
End If
Next
MsgBox k & "个 " & Format(k * 100 / 30, "0.00") & "%"
End If
End Sub
Private Sub Timer1_Timer()
Text3.Text = Val(Text3.Text) + 1
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询