krinpit Posted September 15, 2004 Posted September 15, 2004 I'm trying to itterate through an arraylist, changing the value of each item. In the simplified code below, the values do not change in the arraylist itself. Is there a way around this? :confused: smsg = string.empty For Each x In arrTemp smsg &= x & vbLf Next x Messagebox.show(smsg) For Each x In arrTemp x = 100 Next x smsg = string.empty For Each x In arrTemp smsg &= x & vbLf Next x Messagebox.show(smsg) Quote
Leaders dynamic_sysop Posted September 15, 2004 Leaders Posted September 15, 2004 you are only trying to changed the string value you get out of the array , you need to change the actual array item , eg: Dim strItems As String() = {"item 1", "item 2", "item 3", "item 4", "item 5", "item 6"} '/// add some items to a string array Dim arrlist As New ArrayList arrlist.AddRange(strItems) Dim x As Integer = 0 For x = 0 To arrlist.Count - 1 arrlist(x) = "the new value " & x '/// modify the array item's text. Next Quote
krinpit Posted September 15, 2004 Author Posted September 15, 2004 Hmmm, Just as I feared. I like the For Each construct; the for x = 0 method is a little messier, but it will have to do. Thanks dynamic_sysop 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.