Solved

VB6 Multiple folder selector Dialog

Posted on 2004-08-30
8
345 Views
Last Modified: 2013-12-25
I need a VB6 program or function that presents a user with a Folder Browser that enables the user to select multiple folders by either dragging a box around the folders or shift clicking the desired folders. A collection of path statements should be returned after clicking OK. The user should be able to set an initial path.
0
Comment
Question by:ianmac42
  • 3
  • 3
  • 2
8 Comments
 
LVL 2

Accepted Solution

by:
BlueScreen_ earned 500 total points
ID: 11937756
This will show a message box with all the file you selected.
If you have any question let us know!

Dim initpath As String
Dim filname As String
Dim fileArray() As String

    With CommonDialog1
        .InitDir = initpath  'set the initial path
        .FileName = ""  'rest the file name
        .Filter = "All Files (*.*)|*.*|"  ' change this to your filter
        .flags = cdlOFNAllowMultiselect Or cdlOFNExplorer  ' enable multiselect
        .ShowOpen  'display the open dialog
        filname = .FileName
    End With
       
   ' Each file are separated by a null char( chr$(0)  )
   fileArray = Split(filname, Chr$(0))
       
    ' display all the file you selected
    ' this section can be removed
    For i = LBound(fileArray) + 1 To UBound(fileArray)
        ' the first element is the path
        ' the others are the file name
        MsgBox fileArray(0) & "\" & fileArray(i)
    Next
0
 
LVL 5

Expert Comment

by:brianb99999
ID: 11938276
Hi ianmac42,

Unfortunately, don't have enough time to write it, but, it would be pretty simple (load the folders into a treeview, make the treeview multiselect, return the selected treeview item's in a string).
You need to create an Active X control (using treeview or listview) to do this for you.
A good example of some of the code that will need is on:
http://www.freevbcode.com/ShowCode.asp?ID=6866
Remember when you add the list boxes make them multiselect.

There is nothing within VB or Windows API's that can select multiple folders.

Brian.
0
 

Author Comment

by:ianmac42
ID: 11947007
Brian,
In Windows Explorer in Windows XP I can select multiple folders in the right hand pane. Isn't this functionality available to VB through the Shell object?
0
 

Author Comment

by:ianmac42
ID: 11947350
Bluescreen,
Thanks for the code but it doesn't work. I get the dialog which allows me to select multiple folders but there's no "OK" button to exit the dialog and return the selected path strings. The only buttons available are "OPEN" & "CANCEL", if I click "OPEN" then the last folder that I selected is opened.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 5

Expert Comment

by:brianb99999
ID: 11947694
Hi ianmac42,

Isn't this functionality available to VB through the Shell object?
No - using the shell object simply opens another program and while you can use it to open Explorer - explorer will not return any values to your program.

Bluescreen,
Thanks for the code but it doesn't work. I get the dialog which allows me to select multiple folders but there's no "OK" button to exit the dialog and return the selected path strings. The only buttons available are "OPEN" & "CANCEL", if I click "OPEN" then the last folder that I selected is opened.
The code Bluescreen gave you is to select multiple files not multiple folders.

The suggestion I made earlier is what is commonly used to solve this problem.
The following wont work:
-You can't use the common dialog control - it will select multiple files but not multiple folders.
-You can't use SHBrowseForFolder API - It only allows you to select 1 folder.
-You can't shell to explorer - it won't return any values.
-You can't use FileSystemObject API (You can use it to copy multiple folder - but not select them).

Hope that helps,

Brian.
0
 

Author Comment

by:ianmac42
ID: 12038646
Brian,
Thanks for your help, I've used the CCRP DirTreeView component for the directory browser, MS ListView component for the subdirectory folder list and your recursion program and everything works sweetly. Sorry I doubted you earlier but I had conficting reports.

Ian
0
 
LVL 5

Expert Comment

by:brianb99999
ID: 12040220
Hi Ian,

No problem, glad it helped.
Conflicting reports are a good thing, someone will always find a new way to do something.

Brian.
0
 
LVL 2

Expert Comment

by:BlueScreen_
ID: 12040235
thanks for the points ianmac42.
i feel a little bit bad about getting those points since i give you a solution for files and not for folders like you asked... but i'll be glad if it helped you in any way.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now