Converting complex vars to strings

samm
09-06-2000, 01:12 PM
I have a need to store complex variables as single strings, and then restore them. These are custom type variables, i.e.:

type myvariable
a as int
b as double
c as string
d as boolean
end type


Ideally, I'd like to have a pair of functions of this sort:

string function myvar2string (z as myvar)
myvar function string2myvar (y as string)

for conversion back and forth. I've considered individually converting each var into a string, then concatenating each together, but this seemed kind of tedious since I have
several dozen custom variables, and each would require a separate version of myvar2string.

Any suggestions?

BillSoo
09-06-2000, 01:46 PM
check out the split function

"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder

samm
09-06-2000, 01:55 PM
Interesting.....but parsing the a string into strings isn't the tricky part. It's knowing how many vars are in the custom type (which can change) and converting them into strings to begin with....a sort of sizeof() functions that returns how many vars are in the struct and what type.

Split() could be used to separate the string into individual strings, but wouldn't know what to convert them into.

BillSoo
09-06-2000, 04:26 PM
Well then, assuming that you have control over the text file, you could use something like:

...
type CustomType1
a%=143
b$="this is a string"
c$*5="fixed"
end type

Basically, you have the structure information embedded in the text file.

You could split the text file into individual lines, then parse each line. Maybe make a state machine.

If you had only a few objects, you could use an INI file instead of a regular text file. I find that they tend to be a bit more flexible when it comes to adding or subracting items from types.

"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder

BillSoo
09-06-2000, 04:29 PM
Alternatively, you could make a structure header entry followed by all the data. It might be a bit more compact. Especially since you could save the data as a binary image, unless it contained variable length strings...

"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum