VB.net Saving multiple lists to Settings or TextFiles

Murray Brown
Murray Brown used Ask the Experts™
on
Hi. I am creating multiple lists using code similar to that below. I need to save these lists so that next time the user opens the app they are available. Where is the best place to do this (Settings or Text Files) and what code would I use to do this? Thanks


Dim aList As New System.Collections.Generic.List(Of String)()

aList.Add("one")
aList.Add("two")
aList.Add("three")

Dim bList As New System.Collections.Generic.List(Of String)()

bList.Add("one")
bList.Add("two")
bList.Add("three")
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Solutions Consultant
Commented:
For this instance I would use a text file as it is the simpliest answer.

This link shows how to write to file

http://msdn.microsoft.com/en-us/library/1t4kyezf%28v=vs.80%29.aspx

If you write a ListToString method like
Public Function ListToString(l as List) As String
   Dim s as String, out as string
   out = ""
   For each s in l
      out = out & s & ";"
   Next
   return out   
End Function

Open in new window


This will enable you store the list as semi-colon seperated values - you can use any value you like, then use the split function when you retrive the string to put back into a list

eg

the following will split the string foo and create a generic list

List<String> aList = new List<String>(foo.Split(";"));

Open in new window


Michael
Murray BrownASP.net/VBA/VSTO Developer

Author

Commented:
Thanks very much

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial