Storing stuff - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://staging.qb64phoenix.com/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://staging.qb64phoenix.com/forumdisplay.php?fid=10) +---- Thread: Storing stuff (/showthread.php?tid=1274) Pages:
1
2
|
RE: Storing stuff - SpriggsySpriggs - 12-15-2022 @NasaCow I'd recommend Proton VPN. It's pretty good. RE: Storing stuff - bplus - 12-15-2022 @NasaCow Open file For Input is read only in sequential order from first line to last. Open file for Output is write only and will over write the last file by same name again it writes in sequential order from first line to last. Open file for Binary reads and writes with get and put in byte quantities specified in length of get or put variable value or type. Open file for Random also reads and writes to any part of file but usually of one and same record length setup with UDT using fixed lengths for strings. So I'd say Input / Output is easiest for beginner and you can get very fancy with Binary reading and writing anywhere with any amount of bytes. Data records for 60 students, I doubt there is any difference you could feel for any access method over another. I like Input / Output access because no matter how much faster Binary is, using arrays for processing data is faster than using a file as an array. So with Input / Output you load arrays at start of data session and save data to files at end when done. RE: Storing stuff - bplus - 12-15-2022 That said, there is a really nice way to load and save line record files of variable length strings using Split and Join$ routines. To load: 1. Open file for Binary 2. Read it's size and make a get buffer buff$ = space$(lof(filenum)) 3. Get fileNum, , buff$ 4. close 5. Split buff$, delimiter$, myArr$() MyArr$ now contains all the variable length file lines in an array for processing data in code. but now I have to explain delimiter$ which is Chr$(13) + Chr$(10) for bas and old txt file but some modern txt files now just use chr$(10) or you could just use Chr$(10) and still read it from WP. They separate one "record" or variable length string from another. and MyArr$() needs to be dynamic ie started with REDIM not Dim for the particular Split sub I have in mind: (Dynamic means it can be resized as needed with REDIM _Preserve or just REDIM to clear last array and start with new with same variable name. Code: (Select All) ' note: I buggered this twice now, FOR base 1 array REDIM MyArray (1 to 1) AS ... the (1 to 1) is not same as (1) which was the Blunder!!! Where there is splitting there is complementary Join$ that converts an array into a really long string. That's when you want to file a variable string array back in a single Put for binary or easiest Open for Output and print filenum, the Join$'d string. Then to file data from MyArr$() buff$ = Join$(MyArr$(), Chr$(13) + Chr$(10)) and of course use delimiter$ = Chr$(13) + Chr$(10) because you don't want to do that + for every line! So save a variable string array to file: Open file for output as #filenum Print #filenum, Join$(myArr$(), delimiter$) Close But these methods aren't felt in speed until in 1000's of strings. In summary, it's nice if you have Split and Join$ in your arsenal of tools and know how to use them and, you have a file with maybe 1000's of lines to load or save. |