我正在清理一些已故父亲的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 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结束为空(主要是在长时间的停机或停电之后)。
如果我在If Not SkipUpdate Then
出现EoF错误时可以跳到Line Input #4, adate
行,代码将自行修复
我觉得修复可能非常简单,我只缺乏VB6和错误处理的经验。
答案 0 :(得分:2)
您可以查看EOF:
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
答案 1 :(得分:1)
输入文件的结尾"有时会发生使用print而不是write ...