Results 1 to 4 of 4

Thread: [RESOLVED] Selecting various files in a CommonDialog

  1. #1

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Resolved [RESOLVED] Selecting various files in a CommonDialog

    In a commondialog I set this flag:

    CommonDialog1.FLAGS = cdlOFNAllowMultiselect

    so various files can be selected. Then, in

    CommonDialog1.FileName

    the path and the names of the selected files are returned separated by null characters:

    Path & Chr(0) & File1 & Chr(0) & ... & Chr(0) & FileN

    so that I can retrive the individual file names using a split statement.

    Is there an easier way I'm not aware of?
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  2. #2
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Selecting various files in a CommonDialog

    That would the easiest way, IMHO.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Selecting various files in a CommonDialog

    I agree, and here is how I would do it
    Code:
    Dim i As Long
    Dim sArrFileList() As String
    
    sArrFileList = Split(CommonDialog1.FileName, Chr(0))
    For i = 0 To UBound(sArrFileList())
        List1.AddItem sArrFileList(i)  'Listbox used as an example only
    Next

  4. #4

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Selecting various files in a CommonDialog

    Quote Originally Posted by Hack
    I agree, and here is how I would do it
    Code:
    Dim i As Long
    Dim sArrFileList() As String
    
    sArrFileList = Split(CommonDialog1.FileName, Chr(0))
    For i = 0 To UBound(sArrFileList())
        List1.AddItem sArrFileList(i)  'Listbox used as an example only
    Next
    Yeah, that's more or less my approach. But some care had to be taken anyway. I can't remember what the trouble was so I just transcribe the working code.
    Code:
        ohndc = Split(CommonDialog1.FileName, Chr$(0))
        NFiles = UBound(ohndc)
            If NFiles = 0 Then
                NFiles = 1
                'Working with option base 1
                ReDim FileFullPath(1 To NFiles)
                ReDim File(1 To NFiles)
                FileFullPath(1) = CommonDialog1.FileName
                File(1) = CommonDialog1.FileTitle
            Else
                ReDim FileFullPath(1 To NFiles)
                ReDim File(1 To NFiles)
                PathOnly = ohndc(0) & "\"            
                For i = 1 To UBound(ohndc)
                    File(i) = ohndc(i)
                    FileFullPath(i) = PathOnly & File(i)
                Next
        End If
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width