Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
EOF behaviour
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. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
EOF behaviour
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 "Phil Hibbs" wrote in message ... 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. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Range-name Behaviour | Excel Discussion (Misc queries) | |||
Odd Behaviour with Sub | Excel Programming | |||
Erratic behaviour of [Sh+F10] | Excel Programming | |||
Strange behaviour | Excel Worksheet Functions | |||
Key behaviour | Excel Programming |