dim record (Language Help)

by DickStomp ⌂ @, Europe Netherlands Sassenheim, Saturday, July 19, 2014, 20:43 (1072 days ago)

What I barely need is a
DIM RECORD
A as INTEGER
$B as string *20
END DIM

then
A = 5
$B = "Amount"
LOCATE=5
WRITE RECORD at Location

Even in a structured file we have no possibility to read a RECORD in the RECORDmap or write a RECORDmap in a position of the file.
So we have no database functionality!
If I'm wrong, please show me the way...

--
it must be possible...

dim record

by Jim ⌂ @, Russell, KY, Monday, July 21, 2014, 18:56 (1070 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

dim record

by DickStomp ⌂ @, Europe Netherlands Sassenheim, Tuesday, September 16, 2014, 06:37 (1014 days ago) @ Jim

Dear Jim,
Thank you for your excellent explanation!
Best regards,
Dick

--
it must be possible...

RSS Feed of thread
powered by my little forum