Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod!uakari.primate.wisc.edu!dali.cs.montana.edu!milton!blake.u.washington.edu!dunadan From: dunadan@blake.u.washington.edu (Steven Owen) Newsgroups: comp.sys.apple2 Subject: Applesoft problem: finding the end of a text file Summary: How to do this without ONERR GOTO... Message-ID: <14442@milton.u.washington.edu> Date: 15 Jan 91 12:11:40 GMT Sender: news@milton.u.washington.edu Organization: The Broken Blade Lines: 25 Here's an age-old Applesoft BASIC problem that I've come across while reworking some old code: When reading information from a TXT file, I have yet to find a satisfactory way to determine where the end of a file is. The most common method, I suppose, is to slip in an ONERR GOTO statement just before you start reading data from the file, and reference the line number just after the read command, which usually closes the file and changes the ONERR GOTO line number to its original reference. Another way is to find the file's length, and keep track of how many bytes you've read from the file (along with each CR), and stop when the two are equal. This should work, except in cases where the final line of the program isn't terminated by a RETURN character (this method would work if you're using GETs to retrieve the data, but that would be much too slow). To get the file's length, you can either read the file's directory entry in its parent DIR file (messy, and if the directory is large, this can take a while), or poke a GET_EOF MLI call into memory (faster, but still a little messy, even when using Amperworks' neat &MLI command). It would be nice to have a one or two-line solution, but I don't suppose that I'm going to find something as simple as "IF THEN ...", am I? --Mike Owen, Bladesmith at large