How can i loop tru an Array

Posted on 2005-04-26
Last Modified: 2010-04-23
I have the folowing Code

Dim tmpSelection() As String
Me.openFileDialog1.Multiselect = True
tmpSelection = Me.openFileDialog1.FileNames

which means tmpSelection holds a list of selected files. How can i loop thru these 1 by one ?
Question by:AlexPonnath
    LVL 13

    Expert Comment

    Dim i as string

    For each i in tmpselection
        msgbox (i)
    LVL 13

    Assisted Solution

    Dim ArrayLength, ArrayIndex as Integer

    ArrayLength = tmpSelection.Length
    ArrayIndex = 0

    While ArrayLength > ArrayIndex

    '<execute your code>
    'For Example:  MessageBox.Show(tmpSelection(ArrayIndex))  where ArrayIndex points to your item

    ArrayIndex += 1
    End While
    LVL 13

    Accepted Solution

    Or if you need to keep track of how many you have looped through

    Inculde Windows.VisualBasic

    Dim i as Long

    i = 0
    for i = 0 to ubound(tmpselection)
           msgbox(tmpselection(i) & "This is file # " & i.tostring)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    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…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    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