Qbasicnews.com

Full Version: When to use the different types of files.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I was wanting to save my data when I realised that I din't know anything about the file types and their strengths and weakenesses. Could someone please help me?
Basically, you save stuff in your own format, and file extensions don't matter.
Sory I didn't make my self clear. I was talking about when you open a file for output, binary, random etc.
OUTPUT is just text, I don't really mess with it
BINARY will save data types. This what I use all the time
RANDOM is all over the place. You can access any part you want without having to rewrite all the content. I'm not really familiar with this type, either, so if I got that explanation wrong, don't shoot me.

I guess weaknesses of OUTPUT would be speed and having to parse your data, since it's just text. BINARY you have to remember which order you saved stuff when you load it, but it's not that hard.
I use OUTPUT and INPUT and LINE INPUT a$ and PRINT #1. Easy.
I've only ever used OUTPUT and RANDOM, but I'll get around to learning about BINARY some time in the future

ps: I've modified GIF loaders that used binary, but that doesn't count, does it.
the different OPENning modes that you're interested in. If you want to *write* stuff to a file and then be able to look at it with a text editor and understand what you're looking at, FOR OUTPUT or FOR APPEND might be a good idea. (FOR OUTPUT will cause an already existing file to get replaced. FOR APPEND will cause any data written to an already existing file to get written to the end of it, saving what was already there.) But you can't read *and* write with either of those modes.

If you want to *read* text data from a file, use FOR INPUT. However, you can't output (i.e., write) to a file opened with that mode.

If you want to read *and* write from the same file, use FOR BINARY or FOR RANDOM. The disadvantage there is that you can't generally look at such files with a text editor and see anything too intelligible. Other advantages are, however, that such files tend to be smaller than their text counterparts and they store the data more accurately. (They store the data mirroring the way it's stored in memory, before writing to the file.)
Okay thank you everyone for your help.
RANDOM is crappy. You have to specify a fixed record length and then you can just grab a record with a record number instead of just using BINARY and multiplying by the length of your record structure... lazy bums Wink