Funny, I have recently been thinking of building a set of array tools: Insert, Delete, Append, Sort... but did not consider using MEM which makes good sense for speed.
Can strings be done? How to handle different types? How to handle user defined Record type?
Sorry keybone this might be more than you wanted to get into but building a set of Dbase tools is great idea.
I hear it's better the 2nd time around. :-))
QBDbase library:
https://www.dropbox.com/s/8mouscuqh127vpm/QBDbase.7z?dl=1And a little sample program which reads from the included QBD file (which is the file extension which I chose to stand for a self contained QBDbase file):
'QB64 Code Auto-Generated by the QBDbase Library
'On 08-03-2018
'QBDbase Library coded and designed by Steve McNeill
'smcneill@swva.net
'And is open source and free for all use - both commercial and private -- with no expection of credit needed nor required.
'But if you want to send me a cute picture of a beautiful girl in a swimsuit (swimsuit optional), feel free to use the email above.
'QB64 code starts here:
'$Include:'DataLibraryH.BI'
TYPE QBDdefaultType
' feel free to change this if you want a custom name type DIM MyRecord
AS QBDdefaultType
TypeMem
(0) = _MEM(MyRecord
)
Filehandle = OpenData("SpellList.QBD", 0)
PRINT QBDRecordsUsed
(Filehandle
);
"records exist in database" ReadData Filehandle, i
ReadData Filehandle, i
UnDeleteData Filehandle, i
ReadData Filehandle, i
'$Include:'DataLibraryF.BM'
If you look in the DataLibraryF.BM (the footer file which goes at the end of your code), you'll see that we have all sorts of nice tools already at our disposal with QBDbase. It counts records, add records, deletes records, UNDELETES records (as the above demo illustrates) for when we screw up and delete the wrong record, sorts by field. It packs databases to purge deleted files when we need it to, to minimize file size and memory usage. It allows us to password protect our databases, and to write our own password routines if we want... It can EXPORT the database into several various formats which we can use in different programs such as Word or Excel. (CSV format, TXT format, DBF -- yes, that's native DBF file export capability, BAS GET/PUT format, and even user defined formats...) It tells us how many records we've used, and what we've allocated as a max number of records for our database (which we can change if needed)... It can quickly blank and reset records...
Heck, it even takes an existing QBDbase file and can extract information from it to generate the BAS code required to access that file for you!!
AND, it does even more than all this....
IF somebody has a copy of V1.4 which I had uploaded to [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]. What we have here is an older version which I managed to drag up on my computer, but I can't seem to locate the latest, greatest version which I'd shared and posted for the world to enjoy. My main PC, where I usually work and store all my QB64 stuff, is offline until I replace several of the fans to keep the motherboard/CPU from overheating, and this older version is all I can dig up on my laptop's drives....
If I remember correct, v1.4 also allows us to print out the contents of the database (complete, or just specific records), and it was modified to make use of enhancements which were added to QB64 since the original QBDbase was written waaaaaay back in QB64-SDL times. (Such as not needing the string compare routines which this version accesses via a *.h file.)
If you're looking for a database program for use with QB64, you might consider digging into this one for a little bit, bplus. It might do all you're looking for -- and then some! ;)