Error handling 防止输入超过文件结尾错误
我正在清理我已故父亲的一些Visual Basic 6代码,该代码从气象站获取信息,并将其植入网站的文件中 我想知道如何处理这段代码的EoF错误Error handling 防止输入超过文件结尾错误,error-handling,vb6,runtime-error,Error Handling,Vb6,Runtime Error,我正在清理我已故父亲的一些Visual Basic 6代码,该代码从气象站获取信息,并将其植入网站的文件中 我想知道如何处理这段代码的EoF错误 Open "LastRun.txt" For Input As #4 Line Input #4, adate adate = Trim(adate) flds = Split(adate, "/") If Len(flds(0)) = 1 Then flds(0) = "0" & flds(0) If
Open "LastRun.txt" For Input As #4
Line Input #4, adate
adate = Trim(adate)
flds = Split(adate, "/")
If Len(flds(0)) = 1 Then flds(0) = "0" & flds(0)
If Len(flds(1)) = 1 Then flds(1) = "0" & flds(1)
thismonth = Trim(flds(2)) & "-" & Trim(flds(0))
Close 4
If Not SkipUpdate Then
Open "cvtbmp.sh" For Output As #3
Print #3, "cd /history" & vbLf;
For i = 1 To lastfile
aline = files(i)
oline = "/usr/local/bin/convert -quality 40 " & aline & " " & Replace(aline, ".bmp", ".jpg")
Print #3, oline & vbLf;
Next
Open "LastRun.txt" For Output As #4
Print #4, Date
Close
有时LastRun.txt会以空结尾(主要是在长时间停机或断电之后)。
如果我在行输入#4,adate出现EoF错误时,我可以跳到如果不是SkipUpdate则
行,则代码将自行修复
我觉得修复可能非常简单,我只是缺乏VB6和错误处理的经验。您可以检查:
输入超过文件结尾“当您使用打印而不是写入时,有时会发生…非常感谢,这正是我想要的。
Open "LastRun.txt" For Input As #4
If Not EOF(4) Then
Line Input #4, adate
adate = Trim(adate)
flds = Split(adate, "/")
If Len(flds(0)) = 1 Then flds(0) = "0" & flds(0)
If Len(flds(1)) = 1 Then flds(1) = "0" & flds(1)
thismonth = Trim(flds(2)) & "-" & Trim(flds(0))
End If
Close 4
If Not SkipUpdate Then
Open "cvtbmp.sh" For Output As #3
Print #3, "cd /history" & vbLf;
For i = 1 To lastfile
aline = files(i)
oline = "/usr/local/bin/convert -quality 40 " & aline & " " & Replace(aline, ".bmp", ".jpg")
Print #3, oline & vbLf;
Next
Open "LastRun.txt" For Output As #4
Print #4, Date
Close