Indexed files - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10) +---- Thread: Indexed files (/showthread.php?tid=2140) Pages:
1
2
|
Indexed files - PhilOfPerth - 11-03-2023 I need to create a file that I can access randomly, by specifying a record-number I think this requires an Indexed file, but don't know how to create this. I would need to access it with something like Open "myfile" for input as #1 Input #1, RecNum10 (to access the 10th record). I can do this by reading from the file 10 times, but this would be slow. Any suggestions? RE: Indexed files - a740g - 11-03-2023 I think you can use GET and PUT with RANDOM files to accomplish what you want. RE: Indexed files - bplus - 11-03-2023 You want to open a file for Random (Access) and best if you set it with a fixed length record size. This allows you to read and write records to a record number. Here is a demo for johnno for tracking Blood tests; Code: (Select All) 'Tutorial (with help from Wiki): You create a data entry form for entering the record to file file or reading records out. RE: Indexed files - bplus - 11-03-2023 Here's another demo, it's loading a Random Access file with "fake" data for practice reading and writing. Code: (Select All) _Title "UDT to Random Access File Test" ' b+ 2021-12-24 RE: Indexed files - TerryRitchie - 11-03-2023 I need to add this to the tutorial. I explain sequential flat files but just mention at the end of the lesson that records can be done with RANDOM. I just created a screen sticky note to remind me to do this. Update: Oh yuck: Code: (Select All) TYPE Image Code: (Select All) TYPE Image RE: Indexed files - bplus - 11-03-2023 @PhilOfPerth have you worked with fixed length strings before? Very important in random access files to know about fixed length strings. They help keep you record size the same size for all records with strings in them. RE: Indexed files - bplus - 11-03-2023 I used to do this stuff for work with GW Basic and QB4.5, parts, mold and die inventorys. RE: Indexed files - SMcNeill - 11-04-2023 (11-03-2023, 11:55 PM)bplus Wrote: @PhilOfPerth have you worked with fixed length strings before? Here's an example of a variable length, indexed filesystem at work: https://qb64phoenix.com/forum/showthread.php?tid=142 Fixed length sizes help, but they're not a necessity. RE: Indexed files - JamesAlexander - 11-04-2023 I think there is a better way to do this using the SEEK command. You can do this and go directly here, circumventing all of the random using BINARY symbols instead: file$ = "c:\myfile.dat" OPEN FILE$ for BINARY as #1 Z$= CHR$ (0) ' Null value, Gets 1 symbol at a time. SEEK #1,10 : 'Seek out the 10th symbol of the file. GET #1 , , Z$: 'Get the symbol. Print Z$: 'Prints the symbol CLOSE #1 You can do this too in GWBASIC and Qbasic both, and around the time of GWBASIC, you were limited to a FIELD length of about 128 characters or less... But this is the way to access files efficiently at a byte level (unless you have another more recent way using file direct access). RE: Indexed files - PhilOfPerth - 11-04-2023 (11-04-2023, 01:20 AM)JamesAlexander Wrote: I think there is a better way to do this using the SEEK command. Thanks James. I'll experiment with this. The records are of different lengths, so I may need to use fixed-length strings as also suggested. |