Page 1 of 1
Using "for 1 line", determine EOF?
Posted: Tue Sep 08, 2009 9:31 pm
by Garrett
Really sorry to bother everyone again here. But it just dawned on me here that I'm unsure how to determine when I hit the end of the file. I see in the doc for "read from file" that I can use that command in such a manner to read until EOF, but I am only reading line for line and am unsure if there's a way to toss a switch into my repeat to tell it to stop reading once EOF has been hit.
Any info appreciated.
Thanks again,
~Garrett
Posted: Tue Sep 08, 2009 9:34 pm
by Garrett
Can I use the EOF constant without using it within the "read from file"? If so, does the EOF constant return anything like a 0 or 1 if EOF has been reached?
Like this:
Code: Select all
if EOF is not empty then
answer "we've reached the end of the file so stop looping and get out of repeat loop now"
end if
Posted: Tue Sep 08, 2009 11:37 pm
by bn
Hi Garrett,
from the dictionary:
If the read from file command encounters the end of the file, the result function is set to "eof". If the command was successful and did not encounter the end of the file, the result function is set to empty.
So in your repeat loop you might want to test for the result like in
Code: Select all
if the result is "eof" then exit repeat
regards
Bernd
Posted: Tue Sep 08, 2009 11:40 pm
by Garrett
Wow, I totally missed that too
I think maybe I've been doing too much for today if I'm missing such things now.
Bernd, Thanks a bunch for pointing that out to me.
