Load items in Listbox.

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?
Who is Participating?
SnowFlakeConnect With a Mentor Commented:
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.

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 ?
What programming language ?
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Takamine334Author Commented:
Sorry, I thought I put this in the VB6 section.

It's in VB6
Takamine334Author Commented:
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
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 :-(
Takamine334Author Commented:
It's just text files listed in a folder.
tonym001Connect With a Mentor Commented:
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
Forced accept.

EE Admin
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.