Fix: Input past end of file

 

Error: Input past end of file

 

image

 

Error Causing Code:

 

<script type="text/javascript">
    function readfile(){
        var line
        var fso = new ActiveXObject("Scripting.FileSystemObject");
        file = fso.OpenTextFile("C:\Temp\File1.txt", 1);
        var User = getuserName();
        while (!file.AtEndOfStream) {
            line = file.ReadLine();
            return line
        }
        file.Close();
    }

    function getuserName() {
        var line
        var fso = new ActiveXObject("Scripting.FileSystemObject");
        file = fso.OpenTextFile("C:\Temp\users.txt", 1, false);
        line = file.ReadLine();
        return line
        file.Close();
    }
</script>

 

Fixed Code:

 

<script type="text/javascript">
    function readfile(){
        var line
       var User = getuserName();
        var fso = new ActiveXObject("Scripting.FileSystemObject");
        file = fso.OpenTextFile("C:\Temp\File1.txt", 1);
        while (!file.AtEndOfStream) {
            line = file.ReadLine();
            return line
        }
        file.Close();
    }

    function getuserName() {
        var line
        var fso = new ActiveXObject("Scripting.FileSystemObject");
        file = fso.OpenTextFile("C:\Temp\users.txt", 1, false);
        line = file.ReadLine();
        return line
        file.Close();
    }
</script>

 

 

Explanation:

In  the first code example: you have Scripting.FileSystemObject open for file read, and before closing that file handle attempting to open another Scripting.FileSystemObject though in a different function which causes the file read buffer issues.  Once you finish up file operations only then attempt for instantiating another instance.

 

References:

  1. Input past end of file
  2. AtEndOfStream Property (FileSystemObject)

Leave a Reply

Your email address will not be published. Required fields are marked *