Runtime Error 62: “Input past end of file,” explained and fixed

Error 62, “Input past end of file”, means code tried to read data that is not there: a read executed after the file's end was reached. The standard cause is a loop that reads first and checks later, a fixed read count that assumes more records than the file holds, or a Get aimed past the last record of a random-access file. The file is fine; the code's idea of how much is in it is wrong.

For people who just run the program

  1. Check whether the input file is empty or truncated. A zero-byte file, or one cut short by a failed download or a crashed export, triggers this in code that assumed a header or a minimum number of lines.
  2. Compare with a file that works. If yesterday's file processes and today's fails, diff their sizes first: a much smaller file is usually an incomplete delivery, not a program regression.
  3. Do not pad the file by hand to make it load. Invented lines become real data downstream. Get a complete copy of the file instead.
  4. Report the file's size and origin. “The nightly export arrived at half its usual size” is exactly the fact that closes this case.

For people who write the code

  1. Test EOF before every read, not after. The canonical sequential loop checks the condition at the top:
  2. Do While Not EOF(fn)
        Line Input #fn, lineText
        Process lineText
    Loop
    ' The reverse order (read, then check) reads once too often: error 62.
  3. Never trust an external count. A header claiming 500 records, or a loop bound from a different file's length, is a promise the file may not keep. Drive reads off the file itself: EOF for sequential, LOF(fn) / recordLength for random access.
  4. Watch the Input function and Input #. Input(n, #fn) asking for more characters than remain, and Input # running past the final delimiter, both raise 62. Read the remainder via LOF arithmetic when the tail matters.
An empty file is the extreme case of error 62, and the most common in production. Any read at all on a zero-byte file is past its end. Validate file size at intake and reject empty deliveries with a clear message instead of letting the first read fail cryptically.

If it still happens

If the loop is textbook and error 62 still fires, the file may end mid-record: a truncated random-access file whose length is not a multiple of the record length makes the final Get reach past real data. Compare LOF against the expected multiple to confirm truncation.

Common questions

What is the difference between error 62 and error 53? Error 53 means the file was not found at open time. Error 62 means the file opened fine but a read went past its end. One is about existence, the other about length.

Can a correct loop still hit error 62? Yes, if the file is truncated or empty. The loop guards against over-reading a complete file; a file that ends mid-record defeats record-based reads, which is why intake size checks matter.

Related errors

Runtime Error 59 · Runtime Error 63 · Runtime Error 54