|
Post by mw64 on Jan 27, 2024 11:30:44 GMT
I was wondering if an experienced BASIC programmer could give me some advice... I have created a simple program to monitor numbers chosen at random over a lengthy period of time. It is easy for me to to use this program to add up how many times a certain number has been picked (e.g. #10 has been picked 7 times, #9 5 times!) but I am clueless on how to store this data. Back in the day I was aware that this operation could be done but never advanced my basic programming ability enough to learn how. I am also thinking on the C64 Mini this may be more problematic as there isn't the tape-deck. To re-enter the data manually each time I run the program isn't feasible so I am needing to learn how to do this. Although I'm unsure how this would be possible on the Mini no doubts it will be. However, should it not be, then I may consider attempting to purchase a Maxi! Thank you for your help
|
|
|
Post by Wizart on Jan 27, 2024 11:44:56 GMT
|
|
|
Post by mw64 on Jan 27, 2024 20:20:29 GMT
Thanks... but I thought this group seemed like it 🤔
|
|
|
Post by c64stuff on Jan 27, 2024 23:56:31 GMT
If I'm understanding your question correctly, you have a string of numbers generated and how many times they've each been picked, and want to be able to store them for retrieval the next time you run the program? This is pretty easy to do on tape or disk drive, and so can also be done on the mini or maxi because they simulate those forms of storage on USB through emulation.
It's been years but I wrote some programs in both basic and machine language on the C64 to do this. The simplist way is using a SEQ (sequential file) format. It's only drawback is sequential writes a text file that must be read start to finish sequentially, which means you can't just skip reading it from start to finish to retrieve a specific portion of data and so it can take more time to do it.
This method of data storage has to be used on the tape drive for obvious reasons but is optional on a disk drive. On a disk drive you can jump to the exact portion of data in the file to read which saves time, but it's a more complex file format that takes a few more steps in creating the file in basic and reading desired portions of it later.
I forget the name of this file type, but in your case I think sequential file format is what you'd want to use anyway because you want to read back each number and how many times it occurred in prior program tests. Then the next time you run the program it's just as simple matter of reading the file, running further tests, and then saving the updated file info again.
Just remember to have your program delete the old file first before saving it again. Do not use the save function that overwrites the old file because it has a bug in the kernal and will corrupt the file.
Far as the actual basic commands to do all the above, I can't remember them off hand, but it's fairly straightforward in basic for sequential files. Just refer to the Commodore programming manual for basic. You'll simply be opening the sequential file, using two strings (one for reading the actual number and a second for how many times it popped up in your random number generator last time, and then closing the seq file. Then after you've ran your program to completion again you'll want to have it delete the old file and save it again.
Some might think that you could eliminate storage of the actual number and only store how many times it occurred, because obviously you could use a counter in retrieving the data and the first one would be number one, the tenth one retrieved being number ten, etc. But what if something like the number 58 never occurred in prior program runs? That's why you need two data points stored.
Sequential file format storage and retrieval is super simple and easy to understand in commodore basic, so don't worry if you can do it. It's basically just like programming input prompts from the user in basic with a string. Only difference is you'll be adding a simple line of code in basic to first open the sequential file and the closing the file after reading in the data. Don't forget to do that too or the file will be corrupted if I remember right.
|
|
|
Post by mw64 on Jan 29, 2024 12:48:43 GMT
Thank you very much
|
|
|
Post by c64stuff on Jan 29, 2024 19:33:55 GMT
On second thought it would probably be easier to assign a 0 to each number as how many times it occurred for the very first time you run the program. That would make storage and retrieval easier logistically. Then you'd only need to store each value of occurrence and not the actual number.
Then just use a string as your counter as it writes or reads each value back from the sequential file. First value read back is obviously number 1, 2nd value is 2, etc. With initially assigning each number a value of zero that way each has a 0 as their placeholder in the seq file.
If I remember right you'll want a RETURN after each number so there is an actual return after it to trigger your input read for each as separate string values when reading back the values, just like if you wrote an input prompt for the keyboard you'd be waiting for the user to hit return to finish their input prompt at that prompt. Meaning, you're seq file will look like this if you opened it in a text editor: 0 5 7 0
And so on, as how many times each number occurred. I think if you were wanting to not force a return line after each character in a seq file you'd use a semicolon after what you were writing, just like in printing to the screen. Print "Hello" would cause a return line. Print "Hello"; would not.
It's been years though so I may be wrong on some of these details.
|
|