LB Booster
« Input {from file} »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 04:58am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Input {from file}  (Read 552 times)
joker
Global Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 157
xx Input {from file}
« Thread started on: Dec 9th, 2015, 10:55am »

Someone on the other forum had a problem with "Input Past End" for a file.

Since the INPUT command already knows it is operating on a file, why doesn't the INPUT command already know where the end of the file is?

Why are some BASIC commands so smart but so ignorant at the same time?
User IP Logged

Mystic
Junior Member
ImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 53
xx Re: Input {from file}
« Reply #1 on: Dec 9th, 2015, 3:52pm »

As far as I have seen most programming languages have an End of File (EOF) type check to see if the file you are reading data from has no more data.

There must be a reason why this is not left up to the language to just automatically assume that when you hit the EOF you're done.

It's not a BASIC only issue, but rather most programming languages follow this standard. As for "why" I have no clue. smiley
« Last Edit: Dec 9th, 2015, 3:53pm by Mystic » User IP Logged

- Rick
Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Input {from file}
« Reply #2 on: Dec 9th, 2015, 4:28pm »

on Dec 9th, 2015, 10:55am, pnlawrence wrote:
Since the INPUT command already knows it is operating on a file, why doesn't the INPUT command already know where the end of the file is?

It does. 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. The alternative is to silently ignore the error and return 'non existent' data, but then the cause of the problem wouldn't be so apparent.

Richard.
User IP Logged

joker
Global Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 157
xx 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.
User IP Logged

Rod
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 110
xx 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.
User IP Logged

joker
Global Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 157
xx 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! cheesy)

The "user error" is when one doesn't check for EOF error after each reading of the file.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx 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.
« Last Edit: Dec 10th, 2015, 1:05pm by Richard Russell » User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls