Author |
Topic: Input {from file} (Read 556 times) |
|
joker
Global Moderator
member is offline


Gender: 
Posts: 157
|
 |
Re: Input {from file}
« Reply #3 on: Dec 9th, 2015, 10:12pm » |
|
Quote:| The 'input past end of file' error is intended to be helpful, not an annoyance! If you attempt to read more data than is in the file it is probably a fault in your program, so generating an error aids debugging. |
|
Well, I just thought that it would be more convenient for the INPUT command to only return the data up to the EOF along with the EOF error message.
I don't have my programming computer running, or I would find out if that actually is how it operates.
|
|
Logged
|
|
|
|
Rod
Full Member
member is offline


Gender: 
Posts: 110
|
 |
Re: Input {from file}
« Reply #4 on: Dec 10th, 2015, 11:25am » |
|
The input command works exactly as you describe. It returns the data and sets a flag telling you if you are at the end of the file. The eof() function reads that flag. So if you don't know where you are in the file or how many records there are you should check the eof() before trying to read the next record.
|
|
Logged
|
|
|
|
joker
Global Moderator
member is offline


Gender: 
Posts: 157
|
 |
Re: Input {from file}
« Reply #5 on: Dec 10th, 2015, 11:49am » |
|
Ok, thanks. That seems like the best way to handle it. (Obviously, because it has worked for so long that way! )
The "user error" is when one doesn't check for EOF error after each reading of the file.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 1348
|
 |
Re: Input {from file}
« Reply #6 on: Dec 10th, 2015, 1:02pm » |
|
on Dec 9th, 2015, 10:12pm, pnlawrence wrote:| Well, I just thought that it would be more convenient for the INPUT command to only return the data up to the EOF along with the EOF error message. |
|
The phrase "EOF error" suggests there's some confusion between the EOF() function and the Input past end of file error. They are two separate things and my understanding is that in this thread we are discussing the error not the function.
When any error occurs, control is transferred to the error handler (either the default handler, or a user handler if an ON ERROR or TRY statement is active). Therefore there is no opportunity for the INPUT command to return anything "along with" the error, since it never returns!
There is a standard way to read all the remaining data in a file, without triggering an error (or using the EOF function):
Code:theRest$ = INPUT$(#file, LOF(#file) - LOC(#file)) Richard.
|
|
|
|
|