Trying to search arrayList "fields" and return Index

Hi everyone,

I've got an ArrayList that has been populated with objects defined in our business logic, using data returned from a SQL Stored Procedure.  The app I'm working in is developed in VB.NET 2.0 (yes, I know. :) ).

I'm trying to figure out how to search through that ArrayList for a specific substring of characters in one "field" from the objects in the ArrayList, return the index of that item, and then remove it from the ArrayList.  

I was trying something like this:  

        For i As Integer = 0 To oAcc.FundList.Count - 1
            If oAcc.FundList.Item(i).OptionCode.ToString().Substring(0, 2) = "CD" Then
                oAcc.FundList.RemoveAt(i)
            End If
        Next

Open in new window

Where oAcc.FundList() is my ArrayList and OptionCode is one of the fields in the object contained in oAcc.FundList().

The problem I'm getting is that nothing is being returned, and I verified that there should be something returned based on the data from the Stored Procedure.  

Where am I going wrong?  

Changing the datatype of the Object returning the ArrayList is, unfortunately, not an option here.
LVL 1
Jamie FellrathApplication Developer/Data AnalystAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ken ButtersCommented:
looks like you are removing items from the list you are traversing.

try going backwards.
        For i As Integer =  oAcc.FundList.Count - 1 to 0 step -1
            If oAcc.FundList.Item(i).OptionCode.ToString().Substring(0, 2) = "CD" Then
                oAcc.FundList.RemoveAt(i)
            End If
        Next

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jamie FellrathApplication Developer/Data AnalystAuthor Commented:
Awesome!  Thank you so much, that did the trick exactly!  I think I was staring at this for too darned long!  :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.