Solved

VB6 Multiple folder selector Dialog

Posted on 2004-08-30
8
351 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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
 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Using "ScreenUpdating" 6 63
Excel - Save a copy of work book 13 84
Search combo error "Data Type Mismatch in Criteria Expression" 2 59
MsgBox 4 59
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

813 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

11 Experts available now in Live!

Get 1:1 Help Now