Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CommonDialog

Status
Not open for further replies.

bebig

Technical User
Oct 21, 2004
111
0
0
US
hi,
I have a question about commonDialog
when I select one file, CommonDialog1.FileName shows
..........\Ver2.0\one.html
But, when I select two files, CommonDialog1.FileName shows
..........\Ver2.0rtwo.htmlrone.html
Would you please tell me why it looks different??
Thank you in advance.
-----code------
CommonDialog1.Filter = "Web Files|*.htm;*.html"
CommonDialog1.Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer
CommonDialog1.FileName = vbNullString
CommonDialog1.ShowOpen
FileName = CommonDialog1.FileName & Chr(0) & Chr(0)
 
Hi bebig,

your code does not give me the result you show in your post. However, if you want to process multi-select results from you common dialog, try this code. You need a textbox named Text1 on your form for this:

Code:
    Dim strFileName() As String
    Dim i As Integer
    
    CommonDialog1.Filter = "Web Files|*.htm;*.html"
    CommonDialog1.Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer
    CommonDialog1.FileName = vbNullString
    CommonDialog1.ShowOpen
    strFileName() = Split(CommonDialog1.FileName, Chr(0))
    
    Text1.Text = ""
    For i = LBound(strFileName) To UBound(strFileName)
        Text1.Text = Text1.Text & strFileName(i) & vbCrLf
    Next i

__________________
code is enduring
 
When you select multiple files, the FileName property returns a null-separated string. The first part represnts the folder and the remaining segments represent individual files (without path). You can use the Split function to get the filenames separated in an array and retrieve each filename with complete path.

The 'r' you see in the filename "...\Ver2.0rtwo.htmlrone.html" is not the character r but the null character as seen in the VB tooltip in break mode.

See the following code to get multiple selected filenames.
___
[tt]
CommonDialog1.MaxFileSize = 32767 'increase buffer for multiselect
CommonDialog1.Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer
CommonDialog1.ShowOpen
If InStr(CommonDialog1.FileName, vbNullChar) Then 'multiple files
Dim Files() As String, N As Integer
Files = Split(CommonDialog1.FileName, vbNullChar)
If Right$(Files(0), 1) <> "\" Then Files(0) = Files(0) & "\"
For N = 1 To UBound(Files)
Debug.Print Files(0) & Files(N)
Next
Else 'single file
Debug.Print CommonDialog1.FileName
End If[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top