2016-11-07 85 views
0

我知道是什么原因造成的,但我不确定我需要什么来修复它。其他人在这里写了代码(或借用了它),但我一直在我的脚本中获得第63行字符3处的错误。请注意该行中的ReadAll另一个输入过去文件错误的结尾

<HTA:APPLICATION ID="oMyApp" 
    APPLICATIONNAME="UPSApp" 
    ICON=".\UPS.ico" 
    SCROLL="no" 
    BORDER="thin" 
    SINGLEINSTANCE="yes"> 

<script language="VBScript"> 
Const strStatusFile = "C:\Zscript\fswstatus\fswStatus.txt" 

Dim intTimerID 
intTimerID = window.setInterval("RunAtInterval", 1000) 

Sub Window_onLoad 
    Dim intWidth, intHeight 

    intWidth = 400 
    intHeight = 200 

    Me.resizeTo intWidth, intHeight 
    Me.moveTo ((Screen.Width/2) - (intWidth/2)), ((Screen.Height/2) - (intHeight/2)) 
End Sub 

Sub RunAtInterval 
    Set objFSO = CreateObject("Scripting.FileSystemObject") 

    If Not objFSO.FileExists(strStatusFile) Then Exit Sub 
    Set objFile = objFSO.OpenTextFile(strStatusFile, 1, True) 

    strContent = objFile.ReadAll 
    strContent = Replace(strContent, vbLf, "<br>") 

    If strContent = "QUIT" Then 
    window.Close 
    Else 
    document.formStatus.innerHTML = strContent & "<br>" 
    End If 
End Sub 

<form name = "formStatus" 
+1

另一个可能的重复[Microsoft VBScript运行时错误:输入文件错误结束](http://stackoverflow.com/q/26878933/692942) – Lankymart

+0

在一个循环中读取,将给你更多的控制权,并允许像'Do While not objFile.AtEndOfStream'一样检查。特别推荐如果你正在尝试读取一个大文件,因为'objFile.ReadAll()'效率不高。 – Lankymart

回答

0

你的文件是空的/有0证据长度:

>> n = ".\nix.txt" 
>> goFS.CreateTextFile n 
>> WScript.Echo goFS.GetFile(n).Size 
>> goFS.OpenTextFile(n).ReadAll() 
>> 
0 
Error Number:  62 
Error Description: Input past end of file 

更新WRT评论:

因为它是没有意义的,从一个空文件阅读,你不该”试着去。检查大小为0,并在你的用例中做一些合理的事情。

+0

这就是我正在使用ReadAll引用的目标,根据上面的代码,解决这个问题的最佳方法是什么? –

+0

您需要多少次[回答同一问题](http://stackoverflow.com/a/26880789/692942)?,只需将其标记为dup并继续前进即可。 – Lankymart

相关问题