Results 1 to 4 of 4

Thread: Forlder Browse

  1. #1
    Armbruster
    Guest
    i have a folder browse and say i aready have something in the textbox and i click cancel on the folder browse it deletes the text in the textbox. how do i stop this
    Ummm . . . what?

    Are you using a DirListBox control? Are you using the "click" event for the control to change the contents of the textbox?

    I really want to help, but I need more info. Can you post your code or be a little more specific of exactly what is happening and how it is happening?

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    VB Code:
    1. Option Explicit
    2.  
    3. Public Type BrowseInfo
    4.      hwndOwner As Long
    5.      pIDLRoot As Long
    6.      pszDisplayName As Long
    7.      lpszTitle As Long
    8.      ulFlags As Long
    9.      lpfnCallback As Long
    10.      lParam As Long
    11.      iImage As Long
    12. End Type
    13. Public Const BIF_RETURNONLYFSDIRS = 1
    14. Public Const MAX_PATH = 260
    15.  
    16. Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
    17. Public Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
    18. Public Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
    19. Public Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
    20.  
    21. Public Function BrowseForFolder(hwndOwner As Long, sPrompt As String) As String
    22.      
    23.     'declare variables to be used
    24.      Dim iNull As Integer
    25.      Dim lpIDList As Long
    26.      Dim lResult As Long
    27.      Dim sPath As String
    28.      Dim udtBI As BrowseInfo
    29.  
    30.     'initialise variables
    31.      With udtBI
    32.         .hwndOwner = hwndOwner
    33.         .lpszTitle = lstrcat(sPrompt, "")
    34.         .ulFlags = BIF_RETURNONLYFSDIRS
    35.      End With
    36.  
    37.     'Call the browse for folder API
    38.      lpIDList = SHBrowseForFolder(udtBI)
    39.      
    40.     'get the resulting string path
    41.      If lpIDList Then
    42.         sPath = String$(MAX_PATH, 0)
    43.         lResult = SHGetPathFromIDList(lpIDList, sPath)
    44.         Call CoTaskMemFree(lpIDList)
    45.         iNull = InStr(sPath, vbNullChar)
    46.         If iNull Then sPath = Left$(sPath, iNull - 1)
    47.      End If
    48.  
    49.     'If cancel was pressed, sPath = ""
    50.      BrowseForFolder = sPath
    51.  
    52. End Function
    53.  
    54.  
    55.  
    56. 'usage :
    57. Private Sub Form_Click()
    58.     Dim sFolder As String
    59.     sFolder = BrowseForFolder(Me.hWnd, "select folder")
    60.     If sFolder  <> "" Then Text1.Text = sFolder
    61. End Sub

    I'm guessing here
    -= a peet post =-

  3. #3
    Armbruster
    Guest
    it's not a bad guess!

  4. #4
    Frenzied Member Motoxpro's Avatar
    Join Date
    Sep 2001
    Location
    Spiro, OK
    Posts
    1,211
    all i was missing was the If sFolder <> "" Then Text1.Text = sFolder

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