views:

901

answers:

3

How do you save an array or an arraylist in vb.net using My.Settings?

I cannot find the array type anywhere, even in the browse window.

I absolutely need to be able to save this.

I know I can convert the array to a string, but I do not know how to convert a string to an array. I know that if I were to break it at a delimiter then I could convert a string to an array, but my problem is that any text at all could be stored within the array as a single value, so I cannot pick a delimiter that is likely to be used.

Please help!

+1  A: 

What kind of array? I've had luck using StringCollection for strings. ArrayList works for most anything else (and that's about the only place I'd use arraylist).

Joel Coehoorn
ArrayList, it is now holding any number of strings.Can you explain what stringcollection is and how it works? I only need the methods to derive individual strings by index and to add new strings. Thanks for the help!
Cyclone
StringCollection is just an ArrayList specifically for strings, which sounds _less_ useful at first until you realize that means you also get compile-time type-safety -- things like intellisense support and type checking/verification.
Joel Coehoorn
Thank you! I've got this working now! This is very useful!!!!
Cyclone
Also, since you have been such a huge help with all my questions, if you want a free copy of the script when it is done you can just ask. Its probably not too impressive to you, but it is a useful utility I think people will use (myself included)
Cyclone
A: 

I would either use the StringCollection type, and just convert your elements to/from strings when storing them in my.settings, or use XML Serialization to turn the array in to an xml string, and store that in my.settings.

JamesMLV
+1  A: 

I was also facing the same problem and I came up with a solution to this.

Here are the steps:

  1. Open up the properties of your app and select settings
  2. select the setting name and then where it says type click on the arrow and select browse.
  3. in the browse window type in system.collections.arraylist and hit enter!
  4. there you have your array!

You can use array like this:

your_array_name(here_comes_the_item_no.) = whatever
TheMasterThingMaker
I got it working with a StringCollection as well, but of course yours works for any type of data. Thanks!
Cyclone