Click to See Complete Forum and Search --> : Write contains of listbox
AndyK
February 13th, 2000, 12:24 PM
How can I write contains of 3 listboxes into 1 file without replacing each other's data. I can't write it to specific line, because listbox contains could be modified by user, it could be only one line in listbox, but it could be 20, so I need to get last line that was written by listbox 1, then write listbox 2 and before writting listbox 3, get last line that was written by listbox 2....how????
AndyK
February 13th, 2000, 12:28 PM
Oh, then I need to read all that saved data into appropriate listbox when form is loaded
Chris Eastwood
February 14th, 2000, 03:04 AM
A quick (and easy) way would be to use an INI file (GetPrivateProfileString etc API's).
You could then have sections such as :
[List1]
NumListItems=5
ListItem1=blah
ListItem2=Blah
etc
[List2]
NumListItems=2
ListItem1=
etc
This way, you can easily get the number of items, the last item and still write them in any order you like.
Chris Eastwood
CodeGuru - the website for developers
http://codeguru.developer.com/vb
Chris Eastwood
February 14th, 2000, 03:06 AM
Or you could use XML - if you have IE5 installed, you can easily parse a simple XML File such as :
<LISTBOXES>
<LISTBOX id="1">
<ITEM>List Item 1</ITEM>
<ITEM>List Item 1</ITEM>
<ITEM>List Item 1</ITEM>
</LISTBOX>
<LISTBOX id="2">
<ITEM>List Item 1</ITEM>
<ITEM>List Item 1</ITEM>
</LISTBOX>
</LISTBOXES>
etc - a good place to learn how to parse this file using the M$ XML parser is http://msdn.microsoft.com/xml
Chris Eastwood
CodeGuru - the website for developers
http://codeguru.developer.com/vb
AndyK
February 14th, 2000, 02:27 PM
yeah I was thinking about INI, but I was wondering how to get every item from it into listbox, well thanks for advice, I'll try to figure that out
Chris Eastwood
February 14th, 2000, 03:00 PM
If you use the example I posted :
(using GetPrivateProfileString) :
1. Get NumListItems from ini file
2. For x = 1 to NumListItems
3. Use GetPrivateProfileString for 'ListItem' & x
4. List1.AddItem that string
5. Next
- shouldn't be too difficult - although it means that anyone can edit the file and see how it's structured (and hack it if they feel so inclined)
Chris Eastwood
CodeGuru - the website for developers
http://codeguru.developer.com/vb
AndyK
February 14th, 2000, 04:51 PM
Thanks again. LOL, I don't care if user hack saved file.....it's their problem if he/she will, they'll just have to re-enter all the data back :)
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.