= False
StatusBar1.Panels(1).Text = "Status : Pausing"
End If
End Sub
''---------------------------------------------
Private Sub mnuRestart_Click() ''重新练习
''如果没有开始练习,则退出;否则先卸载动态生成的控件数组,
''然后再开始练习
If mode = "" Then Exit Sub
Dim i As Integer
mode = ""
For i = 1 To rowcount
Unload Label1(i)
Unload Text1(i)
Next
Call mnuStart_Click
End Sub
''---------------------------------------------
Private Sub mnuResume_Click() ''继续练习
''如果练习为中止状态,则继续练习
If mode = "pause" Then
Timer1.Enabled = True
mode = "start"
''Picture1.Enabled = True
StatusBar1.Panels(1).Text = "Status : Starting"
End If
End Sub
''---------------------------------------------
Private Sub mnuStart_Click()
''如果当前正在练习,则退出此过程
If mode <> "" Then Exit Sub
''申明一个文本流和一个文件系统对象
Dim t As TextStream
Dim i As Integer
Dim b As FileSystemObject
''创建一个文件系统对象
Set b = New FileSystemObject
Dim temp As String
''如果当前没有练习文本文件,则采用默认的文本文件进行练习
If filename = "" Then filename = App.Path + "\article\a.txt"
''读一个文本文件
Set t = b.OpenTextFile(filename, ForReading, False)
i = 0: totalchar = 0
''如果没有读完,则继续读
Do While Not t.AtEndOfStream
temp = Trim(t.ReadLine)
''如果当前读的行数据去掉空格后为空,则忽略此行数据
If temp <> "" Then
i = i + 1
''动态生成控件数组,用于显示练习文本数据和创建输入栏
Load Label1(i)
Label1(i).Top = 500 * (i - 1) + i * 5
Label1(i).Left = 20
Label1(i).Caption = temp
''如果显示的练习文本长度大于Picture1的长度,
''则截掉多余的文本
Do While Label1(i).Width + Label1(i).Left > Picture1.Width
Label1(i).Caption = Left(Label1(i), Len(Label1(i).Caption) - 1)
Loop
Label1(i).Visible = True
Load Text1(i)
Text1(i).Top = Label1(i).Top + Label1(i).Height + 20
Text1(i).Left = 20
Text1(i).Width = Picture1.Width - 20
Text1(i).Visible = True
Text1(i).Text = ""
''把输入焦点定位到第一个输入框中
Text1(1).SetFocus
''统计练习文本总字数
totalchar = Len(Label1(i).Caption) + totalchar
''如果练习文本的高度大于Picture1的高度,则不再继续从文本文件中读数据而退出
If Picture1.Height - (Text1(i).Top + Text1(i).Height) < 500 Then Exit Do
End If
Loop
''如果文本文件为空,则退出
If i = 0 Then
t.Close
Exit Sub
End If
t.Close
''练习开始,并且计时开始
rowcount = i
playsec = 0
Timer1.Enabled = True
mode = "start"
StatusBar1.Panels(1).Text = "Status : Starting"
End Sub
''------------------------------------------
Private Sub Text1_Change(Index As Integer)
If mode = "pause" Then Call mnuResume_Click
''如果当前行的打字字数等于当前练习行字数,则跳到下一打字输入行
''如果练习完毕,则弹出对话框,让玩家选择是否存储打字速度数据