Question for loop won't remove all items from listbox or array

evanz

New member
Joined
Feb 2, 2012
Messages
3
Location
West Saint Paul, Minnesota, United States
Programming Experience
3-5
I have an array list declared globally as
Dim OnGraph as new ArrayList

[XCODE]On Error Resume Next
Dim tmp() As String, i As Integer, tmp2() As String, tmpid As String
tmp = Split(lstVials.SelectedItem, ":") 'it will obtain vial name "B366"
tmpid = tmp(1)
For i = 0 To OnGraph.Count
tmp2 = Split(OnGraph.Item(i).ToString, ":")
'This will also obtain "B366"
If tmp2(0) = tmpid Then
OnGraph.RemoveAt(i) 'even though the program hits this line of code it does not remove any items.
End If
Next i​
[/XCODE]

I also get these two debug errors

A first chance exception of type 'System.NullReferenceException' occurred in Greenlight.exe
A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll

I read something about enumeration but i couldnt find any good threads/articles on google.

Any tips?
 
That method didn't work either. When I load the arraylist there are 23 items. the for loop will remove them up until item 12 and then stops. Even though when debugging it hits the ongraph.removeat(i) line. When it hits item 12 it gives me this error

A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
{"Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"}
 
the for loop will remove them up until item 12 and then stops.
Not if you did what I said:
For i = (OnGraph.Count - 1) To 0 Step -1
 
Back
Top