Mene-Mene![]() Member Posts: 1398 From: Fort Wayne, IN, USA Registered: 10-23-2006 |
I'm in need of help on file management. I can make, delete, and write to files fine, but I'm having trouble changing files. Ex. ------------------ |
firemaker103![]() Member Posts: 643 From: Registered: 07-13-2005 |
The easiest way is probably just to write the whole data file over again. ------------------ [This message has been edited by firemaker103 (edited January 10, 2007).] |
samw3![]() Member Posts: 542 From: Toccoa, GA, USA Registered: 08-15-2006 |
I'm not sure what BB is. But if one of those B's stand for basic then you should have a "seek" command. Are all your "slots" the same size? If so you could use "seek" to move the file pointer to the record you want to modify. recPos = seek(playerNum*recSize) And just write the record over again. The problem comes with deletion. At some point you will have to garbage collect. ------------------ |
Mene-Mene![]() Member Posts: 1398 From: Fort Wayne, IN, USA Registered: 10-23-2006 |
Thats my problem. I'm not sure if strings are the same size. BB = BlitzBasic. What your talking about I think is SeekFile() ------------------ |
samw3![]() Member Posts: 542 From: Toccoa, GA, USA Registered: 08-15-2006 |
Well, from my experience, you can't insert space into the middle of a file (easily) in code. So, the two options that come to mind are: 1. make the records the same size and pad to a maximum length of the string. This can wreak major havoc tho if the string happens to go beyond the max len since it will overwrite the start of the next record. 2. rewrite the file each time as firemaker103 suggested There is another option and that would be to try and implement a file insert function that would insert space. You would also need, then to track the positions of the records at the beginning of the file.(since they would be variable) For me it would depend upon how many records I was dealing with and the forseen max size of the file. If it was just a few records, like 1-12, and total file size was under say 1MB, I'd just write the file over again. ------------------ |