Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Range-name Behaviour Peter Excel Discussion (Misc queries) 3 September 16th 08 10:06 PM
Odd Behaviour with Sub NewBike Excel Programming 2 October 9th 06 02:41 PM
Erratic behaviour of [Sh+F10] Terry Pinnell[_3_] Excel Programming 1 August 31st 06 05:59 AM
Strange behaviour Edgar Thoemmes Excel Worksheet Functions 1 February 8th 05 03:20 PM
Key behaviour Rodney[_2_] Excel Programming 1 July 18th 03 11:07 AM


All times are GMT +1. The time now is 04:05 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"