📄 form2.frm
字号:
VERSION 5.00
Begin VB.Form Form2
AutoRedraw = -1 'True
BorderStyle = 3 'Fixed Dialog
Caption = "Form2"
ClientHeight = 7875
ClientLeft = 45
ClientTop = 345
ClientWidth = 10890
LinkTopic = "Form2"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 7875
ScaleWidth = 10890
ShowInTaskbar = 0 'False
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command3
Caption = "退出"
Height = 500
Left = 7680
TabIndex = 4
Top = 6480
Width = 1600
End
Begin VB.CommandButton Command2
Caption = "开始"
Enabled = 0 'False
Height = 500
Left = 4320
TabIndex = 3
Top = 6480
Width = 1600
End
Begin VB.CommandButton Command1
Caption = "抽题"
Height = 500
Left = 960
TabIndex = 2
Top = 6480
Width = 1600
End
Begin VB.TextBox Text2
Height = 320
Index = 0
Left = 1560
TabIndex = 1
Text = "Text2"
Top = 1680
Width = 310
End
Begin VB.TextBox Text1
Height = 270
Index = 0
Left = 1560
TabIndex = 0
Text = "Text1"
Top = 960
Width = 255
End
Begin VB.Label Label1
Alignment = 2 'Center
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 840
TabIndex = 5
Top = 5280
Width = 7815
End
End
Attribute VB_Name = "Form2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public a, b As Single
Private Sub Command1_Click()
For i = 0 To 99
Randomize
k = Int(57 * Rnd + 65)
If k > 90 And k < 97 Then
i = i - 1
Else
Text1(j) = Chr(k)
j = j + 1
End If
Next i
Command2.Enabled = True
End Sub
Private Sub Command2_Click()
Dim m, s, z As Single
Dim i, j, x As Integer
If Command2.Caption = "开始" Then
Command1.Enabled = False
For i = 0 To 99
Text2(i).Locked = False
Next i
a = Timer
Text2(0).SetFocus
Command2.Caption = "结束"
ElseIf Command2.Caption = "结束" Then
b = Timer
c = b - a
j = 0
k = 0
For i = 0 To 99
If Text1(i) = Text2(i) Then
j = j + 1
End If
If Text2(i) <> "" Then
k = k + 1
End If
Next i
x = c \ 60
s = c Mod 60
z = c / 60
m = j / z
If k <> 0 Then
k = Round((j / k) * 100, 2)
End If
Label1.Caption = "本次用时:" & Format(x, "0") & ":" & Format(s, "00") & " " & "每分钟打对" & m & "个字" & " " & "正确率:" & k & "%"
Command2.Caption = "开始"
Command1.Enabled = True
Command2.Enabled = False
For i = 0 To 99
Text2(i) = ""
Text2(i).Locked = True
Next
Text2(0).SetFocus
End If
Cls
End Sub
Private Sub Command3_Click()
End
End Sub
Private Sub Form_Load()
Text1(0).Appearance = 0
Text1(0).Height = 320
Text1(0).Width = 310
Text1(0).Left = 2000
Text1(0).Top = 800
Text1(0).Enabled = False
Text2(0) = ""
Text2(0).Visible = True
Text2(0).Appearance = 0
Text2(0).Height = Text1(0).Height
Text2(0).Width = Text1(0).Width
Text2(0).Left = Text1(0).Left
Text2(0).Top = Text1(0).Top + 350
Text2(0).FontSize = 12
For i = 1 To 99
Load Text1(i) '加载控件text1(i)
With Text1(i)
.Appearance = 0
.Visible = True
.Height = Text1(0).Height
.Width = Text1(0).Width
.Enabled = False
End With
Load Text2(i)
With Text2(i)
.Text = ""
.Visible = True
.Appearance = 0
.Height = Text2(0).Height
.Width = Text2(0).Width
End With
If i Mod 20 = 0 Then
Text1(i).Left = Text1(0).Left
Text2(i).Left = Text1(0).Left
Text1(i).Top = Text1(i - 1).Top + 770
Text2(i).Top = Text1(i - 1).Top + 1105
Else
Text1(i).Left = Text1(i - 1).Left + 331
Text2(i).Left = Text1(i - 1).Left + 331
Text1(i).Top = Text1(i - 1).Top
Text2(i).Top = Text1(i - 1).Top + 350
End If
Next i
For i = 0 To 99
Text2(i).Locked = True
Next i
End Sub
Private Sub Text2_Change(Index As Integer)
Dim i, j, l As Integer
Dim st As String
i = Index
st = Text2(i)
l = Len(Trim(st)) '判断文本框内文本的长度
If l > 1 Then
For j = 1 To l
If i < 99 Then
Text2(i + j - 1).Text = Mid(st, j, 1)
Text2(i + j - 1).MaxLength = 1
If Text2(i + j - 1).Text = Text1(i + j - 1).Text Then
Text2(i + j - 1).ForeColor = &HFF0000
Text2(i + j).SetFocus
Else
Text2(i + j - 1).ForeColor = &HFF&
Text2(i + j).SetFocus
End If
End If
Next j
If i = 99 Then
Text2(i).Text = Mid(st, 1, 1)
Text2(i).MaxLength = 1
If Text2(i) = Text1(i) Then
Text2(i).ForeColor = &HFF0000
Else
Text2(i).ForeColor = &HFF&
End If
End If
Else
If Text2(Index) = Text1(Index) Then
Text2(Index).ForeColor = &HFF0000
If Index < 99 Then
Text2(Index + 1).SetFocus
End If
Else
Text2(i).ForeColor = &HFF&
If Index > 0 And Index < 99 Then
Text2(Index + 1).SetFocus
End If
End If
End If
End Sub
Private Sub Text2_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
If KeyCode = 8 And Index = 0 Then
Text2(Index) = ""
Text2(Index).MaxLength = 0
End If
If KeyCode = 8 And Index <> 0 Then
Text2(Index - 1) = ""
Text2(Index - 1).MaxLength = 0
Text2(Index - 1).SetFocus
End If
If Index > 0 And KeyCode = 37 Then Text2(Index - 1).SetFocus 'keycode=37为 left
If Index < 99 And KeyCode = 39 Then Text2(Index + 1).SetFocus 'keycode=39 为right
If Index > 19 And KeyCode = 38 Then Text2(Index - 20).SetFocus 'keycode=38 为up
If Index < 80 And KeyCode = 40 Then Text2(Index + 20).SetFocus ' KeyCode =40 为 down
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -