30分急求以下vb.net代码,可以使用再加30
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = "" '清空文本框1
Button2.Enabled = True
Button3.Enabled = True
'生成30个97-121的随机数,因为a-z的ASCII是97-121,然后用Chr函数将ASCII码转换为文本
Dim t As New Random
For i As Integer = 1 To 30 Step 1
TextBox1.Text += Chr(t.Next(97, 121))
Next
End Sub
Private StartTime As DateTime
Private EndTime As DateTime
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox2.Text = ""
TextBox2.Enabled = True
Me.ActiveControl = TextBox2
StartTime = Now '记录开始的时间
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
If TextBox2.Text.Length = 30 Then
EndTime = Now '记录结束的时间
TextBox2.Enabled = False
TextBox3.Text = CInt((EndTime - StartTime).TotalSeconds).ToString + "秒" '结束时间-开始时间=间隔
'逐个检验是否正确
'如果正确,则rightcount+1
'完后用rightcount/30,再用Math.Round取4为小数的近似值,小数*100再加一个%就是xx率了。
Dim rightcount As Integer = 0
For i As Integer = 0 To 29 Step 1
If TextBox1.Text(i) = TextBox2.Text(i) Then
rightcount += 1
End If
Next
TextBox4.Text = (Math.Round(rightcount / 30, 4) * 100).ToString + "%"
Button2.Enabled = False
Button3.Enabled = False
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'如果没打完就想结束,为以下代码:
EndTime = Now
TextBox2.Enabled = False
TextBox3.Text = CInt((EndTime - StartTime).TotalSeconds).ToString + "秒"
Dim rightcount As Integer = 0
For i As Integer = 0 To 29 Step 1
If TextBox1.Text(i) = TextBox2.Text(i) Then
rightcount += 1
End If
Next
TextBox4.Text = (Math.Round(rightcount / 30, 4) * 100).ToString + "%"
Button2.Enabled = False
Button3.Enabled = False
End Sub
End Class
还有第二点,楼主你说要点击开始输入后要清除原文框,是否不给原文让用户输入。
此上代码是清除输入框,因为一般打字程序都会给原文对照的吧。