EOF behaviour

P

Phil Hibbs

This is the example code in the help file:

Dim InputData
Open "MYFILE" For Input As #1 ' Open file for input.
Do While Not EOF(1) ' Check for end of file.
Line Input #1, InputData ' Read line of data.
Debug.Print InputData ' Print to the Immediate window.
Loop
Close #1 ' Close file.

In most other languages, the EOF only gets set when you have attempted
to read past the end of a file. So, if the file is empty, this code
would read a blank line and then attempt to print it. In Excel, does
EOF get set right at the start and the loop do nothing? If there is
exactly one line of data, does EOF get set after the first Line Input
command? That is what appears to be happening.

Phil Hibbs.
 
P

Peter T

EOF is generic VB and I guess similar in all languages. Maybe your test file
has a single line break, which you'd get if you wrote it like this -

' kill sFile ' under error handler
FF = Freefile
Open sFile For Append As #FF
Print #FF, ""
Close #FF
Debug.Print FileLen(sFile) ' 2

Regards,
Peter T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top