The most common causes are

Cause 1: you're trying to read before you reach end of file
Solution 1: try testing EOF (see example below)

Cause 2: you opened the file in a wrong mode
Solution 2: correct the mode you're opening this file (see example below)

Open "YOURFILE.TXT" For Input As #1
'To test EOF use EOF function, like this
While not EOF(1)

Don't forget to change YOURFILE.TXT to the path/file name you can access and the 1 number to a position in memory that is not in use (try using FreeFile if you have doubt)

Open "YOURFILE.TXT" For Output As #1
'The line below will produce the error message you saw
Line Input #1, cTeste

This one occurs cause you open the file in OUTPUT mode, but are trying to request a line, it's not permitted. Correct using INPUT mode instead.


Actually, reading a file opened for input and using the input function with either LOF or FileLen could raise this error. Instead of opening for input you would want to open as binary. As an example... (adjust if you installed vb somewhere else...

Dim FName As String, FNumb As Integer, FCont As String
FName = "C:\Program Files\Microsoft Visual Studio\Common\Graphics\Icons\Misc\SECUR02B.ico"
FNumb = FreeFile
Open FName For Input As #FNumb
FCont = Input(FileLen(FName), #FNumb)
Close #FNumb

Now as you will see when you run this code it will give you the error 62, input past end of file but if you adjust for input to for binary, there will be no problem...

Good Luck

This article has been dead for over six months. Start a new discussion instead.