how to select folder using commondialog in visual basic

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2004
Posts: 19
Reputation: Deepa is an unknown quantity at this point 
Solved Threads: 0
Deepa Deepa is offline Offline
Newbie Poster

how to select folder using commondialog in visual basic

 
0
  #1
Nov 15th, 2004
how to select folder using commondialog in visual basic
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 200
Reputation: mnemtsas is an unknown quantity at this point 
Solved Threads: 1
mnemtsas's Avatar
mnemtsas mnemtsas is offline Offline
Junior Poster

Re: how to select folder using commondialog in visual basic

 
0
  #2
Nov 16th, 2004
You can't. Here's some code to allow you to let users do this though:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. 'This module contains all the declarations to use the
  2. 'Windows 95 Shell API to use the browse for folders
  3. 'dialog box. To use the browse for folders dialog box,
  4. 'please call the BrowseForFolders function using the
  5. 'syntax: stringFolderPath=BrowseForFolders(Hwnd,TitleOfDialog)
  6. '
  7. 'For contacting information, see other module
  8.  
  9. Option Explicit
  10.  
  11. Public Type BrowseInfo
  12. hwndOwner As Long
  13. pIDLRoot As Long
  14. pszDisplayName As Long
  15. lpszTitle As Long
  16. ulFlags As Long
  17. lpfnCallback As Long
  18. lParam As Long
  19. iImage As Long
  20. End Type
  21.  
  22. Public Const BIF_RETURNONLYFSDIRS = 1
  23. Public Const MAX_PATH = 260
  24.  
  25. Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
  26. Public Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
  27. Public Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
  28. Public Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
  29.  
  30. Public Function BrowseForFolder(hwndOwner As Long, sPrompt As String) As String
  31.  
  32. 'declare variables to be used
  33. Dim iNull As Integer
  34. Dim lpIDList As Long
  35. Dim lResult As Long
  36. Dim sPath As String
  37. Dim udtBI As BrowseInfo
  38.  
  39. 'initialise variables
  40. With udtBI
  41. .hwndOwner = hwndOwner
  42. .lpszTitle = lstrcat(sPrompt, "")
  43. .ulFlags = BIF_RETURNONLYFSDIRS
  44. End With
  45.  
  46. 'Call the browse for folder API
  47. lpIDList = SHBrowseForFolder(udtBI)
  48.  
  49. 'get the resulting string path
  50. If lpIDList Then
  51. sPath = String$(MAX_PATH, 0)
  52. lResult = SHGetPathFromIDList(lpIDList, sPath)
  53. Call CoTaskMemFree(lpIDList)
  54. iNull = InStr(sPath, vbNullChar)
  55. If iNull Then sPath = Left$(sPath, iNull - 1)
  56. End If
  57.  
  58. 'If cancel was pressed, sPath = ""
  59. BrowseForFolder = sPath
  60.  
  61. End Function
  62.  
  63.  
  64. Form Code
  65.  
  66. Private Sub cmdServerBrowse_Click()
  67. txtDatabasePath.Text = BrowseForFolder(hwnd, "Please select a Server folder.")
  68. End Sub
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 5
Reputation: mex is an unknown quantity at this point 
Solved Threads: 0
mex mex is offline Offline
Newbie Poster

Re: how to select folder using commondialog in visual basic

 
0
  #3
Dec 19th, 2004
Could u pliz let me know as to how do i add this code then, as i keep getting error//

Private Sub Command1_Click()

Dim myfile
Dim i As Integer

For i = 1 To 999
myfile = Dir("C:\" & i & ".bmp")
If Not myfile = i & ".bmp" Then
fSaveGuiToFile ("C:\" & i & ".bmp")
Exit For
End If
Next i

End Sub
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum


Views: 39493 | Replies: 2
Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC