Trying to remove item from array list kicks me out of sub

Posted on 2011-10-06
Last Modified: 2012-05-12
When i run the attached for loop it does fine until it gets to an item containing the word locker.  Then it kicks out of the sub without doing anything else.  Not just the for loop but the entire load sub.
For Each item As String In packlist
            If item.Contains("LOCKER") Then
            End If

Open in new window

Question by:Millkind
    LVL 83

    Accepted Solution

    You need to use a For loop instead of For Each and run in reverse

    For i As Integer = packlist.Count - 1 to 0 step -1
                If packList(i).Contains("LOCKER") Then
                End If
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    Exactly.  The reason it fails is because you can't modify the "packlist" collection while iterating over it with a "For Each".

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now