Load items in Listbox.

Posted on 2007-07-25
Last Modified: 2007-12-19
I know how to open a text file and load the contents into a listbox. How can I select a range of text files and load them into the listbox?
Question by:Takamine334
    LVL 15

    Expert Comment

    if you tell us how you plan to do the first we might be able to help you extend to the later.
    are you talking about client side? server side? using what scripting language ?
    LVL 53

    Expert Comment

    What programming language ?

    Author Comment

    Sorry, I thought I put this in the VB6 section.

    It's in VB6

    Author Comment

    Public Sub mnuOpen_Click()
    With CommonDialog1
        .FileName = ""
        .InitDir = App.Path & "\lists"
        .Filter = "Text Files (*.txt)|*.txt"
        If Len(.FileName) Then
            If mnuClearListBeforeAddingNewUsers.Checked Then List1.Clear
            UserIDFilename = .FileName
            Set fs2 = New FileSystemObject
            Set ts2 = fs2.OpenTextFile(.FileName, ForReading, False)

            Do While Not ts2.AtEndOfStream
                List1.AddItem (ts2.ReadLine)

            Set ts2 = Nothing
        End If
    End With
    Label8 = List1.ListCount & " IDs Loaded"
    End Sub
    LVL 15

    Accepted Solution

    CommonDialog1.Flags = cdlOFNAllowMultiselect

    you can also look here:
    to see hot to handle the common dialg control to allow multi select

    and have a look here: to see how to use the results.

    LVL 2

    Expert Comment

    Hi Tak
    Before I even start -more info required
    How do want to select the files to put in the list box?
    Is it wildcard eg *.txt, is it date related, are the files in a text file, do you want to keep a record of files already processed?

    You see what I mean - more info

    Not that I will get the points another 'expert' will read your response and point you to another link :-(

    Author Comment

    It's just text files listed in a folder.
    LVL 2

    Assisted Solution

    Ok I would do the following

    Private Sub FillListBoxFiles()
    'add a reference to Microsoft Scripting Runtime - scrrun.dll
    Dim mFso As New FileSystemObject
    Dim mFolder As Folder
    Dim mFiles As Files
    Dim mFile As File
    Dim strFolders() As String
    Dim intCount As Integer

    'if you need not wish to add a reference then replace the mFso and all file(s) and folder(s) declarations with object
    'for instance
    'Dim mFso as Object
    'Set mFso = CreateObject("Scripting.FileSystemObject")
    'populate the names of the folders you wish to check
    ReDim strFolders(1)
    'obviously you can make this more sophisticated
    strFolders(0) = "C:\Test"
    strFolders(1) = "C:\Test1"
    For intCount = 0 To UBound(strFolders)
        'Check the folder exists - never trust a user
        If mFso.FolderExists(strFolders(intCount)) Then
            'Set the folder object to the
            Set mFolder = mFso.GetFolder(strFolders(intCount))
            'Set the Files object to files within the folder
            Set mFiles = mFolder.Files
            'Enumerate files
            For Each mFile In mFiles
                'Check the file type - in this case .txt files
                If UCase(Right(mFile.Name, 3)) = "TXT" Then
                    'add to list box
                    List1.AddItem mFile.Name
                    'alternatively add the full path
                    'List1.AddItem mFile.Path
                End If
        End If
    End Sub
    Hope this helps
    LVL 1

    Expert Comment

    Forced accept.

    EE Admin

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
    Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
    In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
    HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

    746 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