Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleLet the user select multiple files with the Common Dialog Control and parse them using Split
Keywordsfiles, multiple files, CommonDialog
CategoriesFiles and Directories
 
Use Split to separate the files returned by the Common Dialog Control.
 
Private Sub Command1_Click()
Dim entries As Variant
Dim dir_name As String
Dim i As Integer

    On Error Resume Next
    dlgFiles.ShowOpen
    If Err.Number = cdlCancel Then
        Exit Sub
    ElseIf Err.Number <> 0 Then
        MsgBox "Error " & Format$(Err.Number) & _
            " selecting files." & vbCrLf & Err.Description
            Exit Sub
    End If

    List1.Clear
    entries = Split(dlgFiles.FileName, vbNullChar)

    ' See if there is more than one file.
    If UBound(entries, 1) = LBound(entries, 1) Then
        ' There is only one file name.
        List1.AddItem entries(LBound(entries, 1))
    Else
        ' Get the directory name.
        dir_name = entries(LBound(entries, 1))
        If Right$(dir_name, 1) <> "\" Then dir_name = _
            dir_name & "\"

        ' Get the file names.
        For i = LBound(entries, 1) + 1 To UBound(entries, 1)
            List1.AddItem dir_name & entries(i)
        Next i
    End If
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated