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?
Takamine334Asked:
Who is Participating?
 
SnowFlakeConnect With a Mentor Commented:
use
CommonDialog1.Flags = cdlOFNAllowMultiselect

you can also look here:
http://vbnet.mvps.org/index.html?code/faq/cdlgmultiselect.htm
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.
http://vb-helper.com/howto_select_multiple_files.html


SnowFlake
0
 
SnowFlakeCommented:
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 ?
Snowflake
0
 
DhaestCommented:
What programming language ?
0
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
0
 
Takamine334Author Commented:
Public Sub mnuOpen_Click()
With CommonDialog1
    .FileName = ""
   
    .InitDir = App.Path & "\lists"
    .Filter = "Text Files (*.txt)|*.txt"
    .ShowOpen
    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)
        Loop

        ts2.Close
        Set ts2 = Nothing
    End If
End With
Label8 = List1.ListCount & " IDs Loaded"
End Sub
0
 
tonym001Commented:
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 :-(
0
 
Takamine334Author Commented:
It's just text files listed in a folder.
0
 
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
'then
'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
        Next
    End If
   
Next
End Sub
 
Hope this helps
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0
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.