Qbasicnews.com

Full Version: best file mode
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
what is the best file mode for accessing as saving, using intigers and strings
I always use BINARY, and save TYPE arrays. It's the most structured way of accessing.
Yeah it is a structured way of accessing and storing data. But be warned that you want to handle strings so when you create a data structure which contains strings you have to specify a length. So after you completely store everything in the binary file and you realise that you want to change the length of the strings then it will be troublesome to do that.
Or you could save your data in a text file if you have to store only little amount of data like this:

Australia, 2563511
USA, 45687
Canada, 8798724
China, 44678
...

I mean just some string and then some integer data. Then you dont have to worry about the length of strings. But then again you wouldnt be able to randomly access any record unless you store the data in an array Big Grin
using binary records not only lets you store integers, but you can store simple fixed length flatfile databases because every record only takes up a certain amount of space.

the only problem is that it pads fixed length strings with null characters so they are a certain length. if you want to compare strings, pull them out and run them through this:

Code:
function denull$ (text$)
  for x = 1 to len (text$)
    a$ = mid$(text$, x, 1)
    if a$ <> chr$(0) then temp$ = temp$ + a$
  next x
  denull$ = temp$
end function
You can also use LTRIM$ on the fixed length string before doing a standard comparison....
d'oh... thanks antoni, the "easy" solution didn't even cross my mind.
I was gonna say... toonski, you did a "whitetiger"! :lol: (he made an INSTR function :lolSmile
Byte (BINARY/RANDOM) is best for speed and smaller size.

It's more difficult than OUTPUT/INPUT because you can't edit it in a text file program (notepad). If you figure out what you're going to put, you can make a special program for your manual file I/O...
Quote:I was gonna say... toonski, you did a "whitetiger"! :lol: (he made an INSTR function :lolSmile
Gah! I've done that. I've made a LEFT$, RIGHT$, INSTR, SPACE$, and STRING$ functions before realising that there were built-in functions. Tongue
Pages: 1 2