Can you write a 'type' to file?

BlitzPlus Forums/BlitzPlus Programming/Can you write a 'type' to file?

Can you write a 'type' to file?

In C and VB you can write struct to file. Can't seem to be able to do that in blitzbasic.

Nope, you'll have to "take the type apart" and save all its elements individually. Then you have to load the elements back in order to recreate the types. It's a bit of a hassle.

Nope, you'll have to "take the type apart" and ...


or... Yes. just use

writeline file,str(type.mytype)


decoding it once saved is your problem - unfortunately there isn't an easy 'loadType' command

I take it something like
ReadLine file,Val(type.mytype)
doesn't work as nicely as Str$ does ;]

Wow, that does work. My bad. Doesn't look like you can save Blitz arrays this way (it transliterates them as "???"), but everything else works fine.

You can save the data with Str(), but it is more trouble that it is worth.
There is no provision for reading it back.
Also, floating point values saved as strings get rounded to six digits.
So they will usually not read back exactly.

The best way to read and write type objects is to create your own functions.