dim record (Language Help)

by Jim ⌂ @, Russell, KY, Monday, July 21, 2014, 18:56 (1072 days ago) @ DickStomp

Dick,

The functionality exists to open a file for "binary" io and then read and write individual bytes from it.

Below is a sample program using a function and a subroutine to read fixed length indexed blocks of text to and from a file. This looks like the functionality you were describing.

# fixed length text file IO
# j.m.reneau 2014-07-21

# DEMO ONLY WORKS WITH ASCII DATA

openb 0, "testdata.dat"
call writerecord(0,10,0,"one")
call writerecord(0,10,1,"two")
call writerecord(0,10,2,"three")
call writerecord(0,10,3,"four")
#
print "file"
for t = 0 to 3
print '"' + readrecord$(0,10,t) + '"'
next t
#
call writerecord(0,10,2,"three changed")
#
print
print "file as changed"
for t = 0 to 3
print '"' + readrecord$(0,10,t) + '"'
next t
#
close 0

function readrecord$(f, z, n)
# f file number - opened with openb
# z record size
# n record number (0...)
seek f, n*z
rec$ =""
for t = 1 to z
rec$ += chr(readbyte(f))
next t
return rec$
end function

subroutine writerecord(f, z, n, rec$)
# f file number - opened with openb
# z record size
# n record number (0...)
# rec$ record to write (padded with spaces)
while length(rec$)<z
rec$ += " "
end while
seek f, n*z
for t = 1 to z
writebyte f, asc(mid(rec$,t,1))
next t
end subroutine

You can also use the SQLite database functionality to actually create a real database and use SQL statetements to access your data. An example can be found in the documentation at http://doc.basic256.org/doku.php?id=en:dbopen

Hope this helps.

Jim


Complete thread:

 RSS Feed of thread

powered by my little forum