How to read a txt file in BBx4

186 Views Asked by At

I have a >30 year old program in BBx what need to read something outside it's own database. Actually it must be something very simple like

txt$ = read (message.txt) print txt$

However there isn't any documentation available. So my question is: How can i read a plain txt file in to BBx4

2

There are 2 best solutions below

0
On BEST ANSWER

simple open the file and read it with READ RECORD

open (1,err=linenr) "message.txt"    
read record (1,siz=1,end=linenr) txt$

opens on channel 1, linenr=line to go when there is an error *siz=1 reads 1 character siz=100 reads 100 etc. end where to go when end of file is detected.

0
On

You can read an ASCII file line by line in a loop, as follows:

ch=unt
open (ch)file$
while 1
    read (ch,end=*break)line$
    if line$="" then
        continue
        rem if the line is empty, skip it
    fi
    
    print line$
    
wend
close (ch)

If you know that the content of the file will fit in the memory, you can read it in one:

ch=unt
open (ch)file$
read record (ch,siz=dec(fin(ch)(1,4)))content$
close (ch)
print content$

The fin(ch) is the file information string, bytes 1-4 are the actual file length in bytes (for an ASCII file).