主题:文件操作为什么老出错,导入内容不对
mahailiang
[专家分:0] 发布于 2010-06-27 11:30:00
代码:
Dim x(4) As String * 104
Dim StartTime As String
Dim t1 As Long
Dim sum As Long
Private Sub Form_Load()
Timer1.Interval = 1000
Timer1.Enabled = True
StartTime = Time
Call Import
Lspeed.Caption = "0 WPM"
End Sub
Private Sub Text1_Change(index As Integer)
Dim sub1, sub2 As String '定义 存放字符串的变量sub1和 sub2
Dim plong As Integer '定义存放picture中字符串长度的变量
Dim count As Long
count = 0: sum = 0
For k = 0 To 4
plong = 100 '将picture中字符串的长度存入plong
len1 = Len(Text1(k).Text) '将text中输入的字符串长度存入len1
For i = 1 To len1
sub1 = Mid(Text1(k), i, 1) '从text中i位置开始取一个字符
sub2 = Mid(x(k), i, 1) '从picture中从i开始取一个字符
count = count + 1: sum = sum + 1
If sub1 <> sub2 Then '当text中输入的字符和picture中的不一样的时候,将picture中的该字符重新打印并显示为红色
p1(k).ForeColor = vbRed '设置picture的前景色为红色
p1(k).CurrentY = 10 '定位x的当前位置
p1(k).CurrentX = (i - 1) * 8 '定位x的当前位置
p1(k).Print sub2 '将输错的字符在picture中用红色重新打印
count = count - 1
End If
If plong = len1 Then '一行输完后的处理
If k + 1 <= 4 Then
Text1(k + 1).SetFocus
plong = 0: len1 = 0
Else
p1(k).Cls
Text1(k) = ""
End If
End If
Next i
plong = 0: len1 = 0
Next k
Lright.Caption = Format((count / sum) * 100, "0.00") & "%"
End Sub
Private Sub Import()
For i = 0 To 4
Open App.Path + "\english.txt" For Input As #1
Line Input #1, x(i)
p1(i).CurrentY = 10
p1(i).Print x(i)
Close #1
Next i
End Sub
Private Sub Timer1_Timer()
Dim intS As Long
intS = Val(DateDiff("s", StartTime, Time))
Ltime.Caption = Format(intS \ 3600, "00") & ":" & Format((intS Mod 3600) \ 60, "00") & ":" & Format(intS Mod 60, "00")
t1 = Val(intS) \ 60
Lspeed.Caption = sum / (t1 + 1) & "WPM"
End Sub
请大侠帮我改改
回复列表 (共11个回复)
沙发
孙瑞 [专家分:590] 发布于 2010-06-27 15:42:00
把几乎所有的自己定义的变量的意思都解释一下吧,不要让我们猜……
板凳
孙瑞 [专家分:590] 发布于 2010-06-27 16:02:00
Private Sub Timer1_Timer()
Dim intS As Long
intS = Val(DateDiff("s", StartTime, Time))
Ltime.Caption = Format(intS \ 3600, "00") & ":" & Format((intS Mod 3600) \ 60, "00") & ":" & Format(intS Mod 60, "00")
t1 = Val(intS) \ 60
Lspeed.Caption = sum / (t1 + 1) & "WPM"
End Sub
【t1 = Val(intS) \ 60】应该改成【t1 = Val(intS) / 60】
4 楼
孙瑞 [专家分:590] 发布于 2010-06-27 21:00:00
????空回复?
5 楼
mahailiang [专家分:0] 发布于 2010-06-27 23:06:00
Dim x(4) As String * 104 '定义数组x存放从文件中读出的内容
Dim StartTime As String '定义存放计时器的起始时间的变量
Dim t1 As Long '定义存放打字耗时的变量
Dim sum As Long '定义存放统计总字数的变量
Private Sub Form_Load()
Timer1.Interval = 1000 '设置定时器间隔为1秒
Timer1.Enabled = True
StartTime = Time '设置起始时间为当前时间
Call Import '调用函数向p1控件数组导入内容
Lspeed.Caption = "0 WPM" 'Lspeed是用于显示速度的控件label,设置初值为0wpm
End Sub
Private Sub Text1_Change(index As Integer)
Dim sub1, sub2 As String '定义 存放字符串的变量sub1和 sub2
Dim plong As Integer '定义存放picture中字符串长度的变量
Dim count As Long 'count用于统计输入的正确字符
count = 0: sum = 0 '设置它们的初值
For k = 0 To 4
plong = 100 '将picture中字符串的长度存入plong
len1 = Len(Text1(k).Text) '将text中输入的字符串长度存入len1
For i = 1 To len1
sub1 = Mid(Text1(k), i, 1) '从text中i位置开始取一个字符
sub2 = Mid(x(k), i, 1) '从picture中从i开始取一个字符
count = count + 1: sum = sum + 1
If sub1 <> sub2 Then '当text中输入的字符和picture中的不一样的时候,将picture中的该字符重新打印并显示为红色
p1(k).ForeColor = vbRed '设置picture的前景色为红色
p1(k).CurrentY = 10 '定位x的当前位置
p1(k).CurrentX = (i - 1) * 8 '定位x的当前位置
p1(k).Print sub2 '将输错的字符在picture中用红色重新打印
count = count - 1
End If
If plong = len1 Then '一行输完后的处理
If k + 1 <= 4 Then
Text1(k + 1).SetFocus
plong = 0: len1 = 0
Else
p1(k).Cls
Text1(k) = ""
End If
End If
Next i
plong = 0: len1 = 0
Next k
Lright.Caption = Format((count / sum) * 100, "0.00") & "%" '用于显示正确率的控件label
End Sub
Private Sub Import()
i=0
Open App.Path + "\english.txt" For Input As #1
do while i<=4 and not eof(1)
Line Input #1, x(i)
p1(i).CurrentY = 10
p1(i).Print x(i)
i=i+1
loop
Close #1
End Sub
Private Sub Timer1_Timer()
Dim intS As Long
intS = Val(DateDiff("s", StartTime, Time))
Ltime.Caption = Format(intS \ 3600, "00") & ":" & Format((intS Mod 3600) \ 60, "00") & ":" & Format(intS Mod 60, "00") 'ltime用于显示文字输入开始后的时间
t1 = Val(intS) / 60
Lspeed.Caption = sum / (t1 + 1) & "WPM"
End Sub
6 楼
mahailiang [专家分:0] 发布于 2010-06-27 23:27:00
补充点问题:像前面那个界面如果一页的文字都输完后,如何实现换一页再输入的效果,还有我那个界面打字错的会将原来的字再用红色重新打一次,但如果将打错的删除时,已经打错的仍然是红色,怎么使他恢复原来的黑色呢。
7 楼
mahailiang [专家分:0] 发布于 2010-06-27 23:29:00
我用goole浏览器打开回复时回复框中数不进文字,一不小心给提交了
8 楼
guoyong_cy [专家分:3050] 发布于 2010-06-28 13:02:00
做的什么东西,为什么一开始就搞这么复查
为什么不先做一个简单的TEST?
9 楼
mahailiang [专家分:0] 发布于 2010-06-28 22:43:00
是一个文字测试软件
10 楼
柚子蜜茶 [专家分:20] 发布于 2010-06-30 20:17:00
现在找对象一定要看仔细一些,因为现在不男不女的人太多了!
我来回复