Thanks to Bill Thoen! That's it, exactly what I was after! Opening the file for binary input, and then using Get to read one character at a time has solved my problem.
I found that using Line Input reads only up to the first instance of a CR character, and thus impossible to test for it's presence. However my text file has records which may contain 2 or 3 or 4 imbedded CRs before the ACTUAL end of line. Hence the need to read one character at a time, its imperative I differentiate between a single CR, and a CR+LF. Here's the code just in case anyone's interested: =============================================================== Sub ReplaceCRwithComma Dim s1 as string *1, s2 as string Define LF Chr$(10) 'Line feed Define CR Chr$(13) 'Carriage return Define QT Chr$(34) 'Double quote Open File "MyInput.TXT" For binary Access Read as #1 Open File "MyOutput.TXT" For output as #2 Do Get #1,,s1 if eof(1) then exit do end if If s1 = CR then 'Read the next character and test if its a Line Feed. 'If it is, then this is a legitimate end of line. Get #1,,s1 If s1 = LF then Print #2, s2 s2 = "" Else 'Replace the Carriage Return with a comma. s2 = s2 + "," + s1 end if Else s2 = s2 + s1 end if loop Close File #1 Close File #2 End Sub =============================================================== Thanks to everyone else who responded too. Peter Zyczynski Insight.GIS Australia Ph: (03) 6244-7344 Fax: (03) 6244-7028 [EMAIL PROTECTED] -----Original Message----- From: Bill Thoen [mailto:[EMAIL PROTECTED]] Sent: Tuesday, 23 April 2002 1:09 AM To: [EMAIL PROTECTED] Subject: Re: MI-L MBX - text file reading Open the file as binary and you could read it one character at a time with get #1,,c where #1 is the file handle and c is declared as string*1. Although this is simple, it's VERY slow. If your files are big, then you should read in bigger chunks, parsing them for the string chr$(12)+chr$(10)+"" and assembling the lines that way. When you get to a spot when the end of the file is too close to read a whole chunk (e.g. string*255), then revert to the one-char-at-a-time approach. -- - Bill Thoen ------------------------------------------------------------ GISnet, 1401 Walnut St., Suite C, Boulder, CO 80302 tel: 303-786-9961, fax: 303-443-4856 mailto:[EMAIL PROTECTED], http://www.gisnet.com ------------------------------------------------------------ Peter Zyczynski wrote: > > Hi all, > > Can any of you budding programmers out there tell me if its > possible to read a text file one character at a time, as > opposed to a whole line at a time? > > My text file has occurrences of the carriage return > character (which doesn't necessarily represent an end of > line), as well as carriage accompanied by a line feed > character (these represent end of line) > > I need to test for a carriage return with an accompanying > line feed. MBX thinks that a single CR is end of line - my > nemesis! > > Thanks, > > Peter Zyczynski > Insight.GIS > Australia > Ph: (03) 6244-7344 > Fax: (03) 6244-7028 > [EMAIL PROTECTED] > --------------------------------------------------------------------- List hosting provided by Directions Magazine | www.directionsmag.com | To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]