Inputing beyond eof

 BBS: Inland Empire Archive
Date: 02-19-94 (07:51)             Number: 391
From: RON PIERCE                   Refer#: 369
  To: ADRIAN WALKER                 Recvd: NO  
Subj: Inputing beyond eof            Conf: (2) Quik_Bas
AW>My problem is that every so often the input file contains an ASCII 26
AW>(right arrow) which the program then reads as an EOF, and will not input
AW>beyond that point.

        Adrian, you will find relief by creating a buffer
to read the contents of the file into then scan the buffer
to retrieve each LINE of text (assuming the file you are
reading is a CR/LF delimited TEXT file).  You will need to
track the buffer position AND the file position.

'
============================================================
============= Fhandl% = FREEFILE Fptr&   = 0 Done% = 0 cr$
= CHR$(13)

OPEN MyTxtFile$ FOR BINARY ACCESS READ SHARED AS #Fhandl% Size& = LOF(Fhandl%)

DO
   Blen% = 4096

   IF Size& - Fptr& < Blen% THEN
      Blen% = Size& - Fptr&
      Done% = -1
   END IF

   Buffer$ = STRING$(Blen%, 32)
   GET #Fhandl%,,Buffer$
   Fptr& = SEEK(Fhandl%)

   BufPtr% = 1

   DO
      a% = INSTR(BufPtr%, Buffer$, cr$)
      IF a% > 0 THEN
         Text$ = MID$(Buffer$, BufPtr%, a% - BufPtr%)
                 ' Do something With text$ now...
         BufPtr% = a% + 2     ' SKip over the CHR$(10) after the cr$
      ELSE

      ' Now you should have the picture.  When there is NO cr$ found
      ' in the buffer you can either backup the file pointer (Fptr&)
      ' To just after the last string retrieved by subtracting the
      ' remaining bytes in Buffer$ from Fptr& or use the remaining
      ' bytes in buffer$ at the beginning of your next buffer$

         EXIT DO
      END IF

   LOOP
LOOP UNTIL Done%
  CLOSE Fhandl%
' =================================================================
   I hope this helps a bit.  Code untested but should give you some
   insight on buffering a text file.

           Ron Pierce

$$60
--- Maximus 2.01wb
 * Origin: Imperial Rome * Welcome to the Empire (1:229/424)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET