Drstein99 Posted October 30, 2003 Posted October 30, 2003 I want to declare an array of strings, I dont know how may will ever be, as little as 1 but may be over 50, throughout the execution of the program. Dim sBackPage() As String Now I want to ADD some strings to the list, and remove some strings from the list - how do I do that? :confused: Quote www.DRSTEIN99.com www.RAIDGEAR.net www.THERE.com -> Tell them DrStein99 sent ya!
Leaders dynamic_sysop Posted October 30, 2003 Leaders Posted October 30, 2003 you could try an arraylist , they are pretty cool and can be added to / removed from the same as a listbox etc... eg: Dim arrlist As New ArrayList() Dim strStrings() As String = {"item1", "item2", "item3"} arrlist.AddRange(strStrings) arrlist.Remove("item2") MessageBox.Show(arrlist.Count) Quote
Drstein99 Posted October 30, 2003 Author Posted October 30, 2003 I actually found a "collection" object, does exactly what I need: Dim sBackPage As New Collection sBackPage.Add("One") 'adds a page sBackPage.Add("Two") 'another sBackPage.Add("Three") ' and another sBackPage.Remove(sBackPage.count) ' removes the last page It works good, you think I have any problems with memory usage? I'm not too keen on working with objects TOO much, but what I do know is if I don't dispose or release certain things it makes a dirty mess. Quote www.DRSTEIN99.com www.RAIDGEAR.net www.THERE.com -> Tell them DrStein99 sent ya!
CattleRustler Posted November 9, 2003 Posted November 9, 2003 if you are working in vb.net then everything is an object, you need not dispose your objects - that's what the GarbageCollector does for you - kills objects in memory when they are no longer needed, unlike vb6. Quote mod2software Home of the VB.NET Class Builder Utility - Demo and Full versions available now!
inzo21 Posted November 12, 2003 Posted November 12, 2003 watch with collection Hey there, I used a StringCollection CLass for teh same purpose - which is similiar or exactly what I think you might be using. Just a heads up with this class. One, yes it gets picked up by the GC - but there are some erratic behaviors if you don't release resources using it when you are trying to read information into it (from a file per se). Two: The collection object is great when the array is about 150 or so elements in length - after that, performance gets less efficient. Also, you can't perform array methods (like sort) on a collection - you need an array or an arraylist. For that, try wrapping the collection into an arraylist using the ArrayList.Adapter method. For example. dim alist as ArraList = ArrayList.Adapter(your_collection_var) alist.Sort \\ or any other method to call on it alist.nothing \\ when finished with the wrapper. okay - just a jeads up. Hope it was helpful! inzo Quote he who forgets will be destined to remember... (E.Vedder)
Drstein99 Posted November 12, 2003 Author Posted November 12, 2003 I'm not working with that many members, so I hope i'm in the clear. Thanks for the stringcollection advice, i'll switch over to string collection instead of the collection which is probably a collection of objects. As far as wrapping collections into an arraylist, well - that stuffs above my head and I don't understand any of it. Quote www.DRSTEIN99.com www.RAIDGEAR.net www.THERE.com -> Tell them DrStein99 sent ya!
*Experts* mutant Posted November 12, 2003 *Experts* Posted November 12, 2003 Some collection classes actually use the ArrayList as their internal list that they use, and are then simply customized. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.