From: mp on
Given a form with a reference to a list of strings...

What would be the easiest way to 'serialize' the contained data (list of
strings)
by easiest i mean easiest for a dummy like me to learn how to do

so on program start the form could look on disk to find it's last saved
state of collected strings

i could just write to text file (tacky but it does meet the easy
requirement)
or ini file (i could figure that out - have done once maybe)
or xml file (i maybe could figure that out - have read about)

since it's just a prog for me it doesn't have to be elegant but i wouldn't
mind learning some new hip technique

thanks for any ideas
mark


From: GS on
mp explained :
> Given a form with a reference to a list of strings...
>
> What would be the easiest way to 'serialize' the contained data (list of
> strings)
> by easiest i mean easiest for a dummy like me to learn how to do
>
> so on program start the form could look on disk to find it's last saved state
> of collected strings
>
> i could just write to text file (tacky but it does meet the easy requirement)
> or ini file (i could figure that out - have done once maybe)
> or xml file (i maybe could figure that out - have read about)
>
> since it's just a prog for me it doesn't have to be elegant but i wouldn't
> mind learning some new hip technique
>
> thanks for any ideas
> mark

Nothing 'tacky' about using a text file since that's what an ini and
xml file is anyway. What matters is how you want to work with the data
read/write wise, in terms of what best suits your app. Determining
factors would also be how the data is stored on the form, and whether
the form is used to update the data during runtime dynamically, or
place it somewhere else (like an array) for runtime use and then update
to file at shutdown. Or.., any number of countless other scenario
possibilities.

<IMO> If it's app settings data that's required at startup, and/or
edited during runtime, and then updated to file at shutdown, usually an
INI file is used as an easy alternative, for example, than say the
Registry. Ini files require using the PrivateProfile functions from the
WinAPI "kernel32.dll".

Text files only require using VB's built-in I/O features. It's a fairly
trivial task to load each line into an array using the Split()
function. Text files can also be set up to work with ADO when the data
can be delimited, by ensuring the first line in the file contains field
headings (also delimited) same as would be used in a database.

Xml files are a bit more complex to work with via VB's built-in I/O
features, but there's APIs that can make it (almost) as simple as
working with INI files. The challenge here will be working with the
string literals correctly so the file content also correctly contains
its xml string literals. This, of course, is only required if you
expect to use the file as XML. If you just like the format of it then
leave the quote characters out and just parse according to "<", ">",
"</", or "/>"!

So.., pick yer poison!

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


From: Cor Ligthert[MVP] on
Which language version of VB are you using.

List of String is a class from .Net framework 2.0 and latter ( VB 2005 and
latter).

But it can of course also be your description of an array of strings in VB6


"mp" <nospam(a)thanks.com> wrote in message
news:hv9am3$8p8$1(a)news.eternal-september.org...
> Given a form with a reference to a list of strings...
>
> What would be the easiest way to 'serialize' the contained data (list of
> strings)
> by easiest i mean easiest for a dummy like me to learn how to do
>
> so on program start the form could look on disk to find it's last saved
> state of collected strings
>
> i could just write to text file (tacky but it does meet the easy
> requirement)
> or ini file (i could figure that out - have done once maybe)
> or xml file (i maybe could figure that out - have read about)
>
> since it's just a prog for me it doesn't have to be elegant but i wouldn't
> mind learning some new hip technique
>
> thanks for any ideas
> mark
>
>
From: Mayayana on
I'm using a method I like a lot. I think I
originally got the idea from Larry Serflaten.

It turns out that a UDT can be read from/written
to disk as a binary file. Despite the string values
being pointers, VB will nevertheless write all data
stored in the UDT in serial fashion!

So I declare a large UDT in the program to hold
various settings of all types. At startup I fill the
UDT by reading in a settings.dat binary file. If the
file isn't there I write it with an empty UDT, which
accords with default settings. At program close I
write the current UDT to disk. During operation I
refer to the UDT members to get or change settings
values.

It's a very clean, simple method with room for
expansion, and it provides intellisense at design
time for referencing settings variables.



| Given a form with a reference to a list of strings...
|
| What would be the easiest way to 'serialize' the contained data (list of
| strings)
| by easiest i mean easiest for a dummy like me to learn how to do
|
| so on program start the form could look on disk to find it's last saved
| state of collected strings
|
| i could just write to text file (tacky but it does meet the easy
| requirement)
| or ini file (i could figure that out - have done once maybe)
| or xml file (i maybe could figure that out - have read about)
|
| since it's just a prog for me it doesn't have to be elegant but i wouldn't
| mind learning some new hip technique
|
| thanks for any ideas
| mark
|
|


From: Larry Serflaten on

"mp" <nospam(a)thanks.com> wrote
> Given a form with a reference to a list of strings...
>
> What would be the easiest way to 'serialize' the contained data (list of
> strings)
> by easiest i mean easiest for a dummy like me to learn how to do

There is not enough information to determine the best approach.

1. Are the strings all the same size?
2. Does the list change size at any time?

1a If the strings are the same size, make one big string out of all of
them and save that to a file. When you read it back in, you just
chop up the data to get your original strings.

2a If the list changes size, just print them to a file and read them back
in. The file itself will determine how many strings are required.
If the list always has the same number, check out Mayayana's reply.

How would you do it? The best way (for you) will always be a method
you fully understand... ;-)

LFS