Using "for 1 line", determine EOF?

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
Garrett
Posts: 386
Joined: Sat Apr 08, 2006 8:15 am
Contact:

Using "for 1 line", determine EOF?

Post 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
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
Garrett
Posts: 386
Joined: Sat Apr 08, 2006 8:15 am
Contact:

Post 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
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4219
Joined: Sun Jan 07, 2007 9:12 pm

Post 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
Garrett
Posts: 386
Joined: Sat Apr 08, 2006 8:15 am
Contact:

Post 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. :-)
'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.)
Post Reply