Common Dialog Control - VB 6

How do I use the Common Dialog Control to return folder names - I don't want to have to select a file then draw the path name back off because I am setting a destination for saving / moving files ... a volume/file manger application

Thanks
C

Comments

  • : How do I use the Common Dialog Control to return folder names - I don't want to have to select a file then draw the path name back off because I am setting a destination for saving / moving files ... a volume/file manger application
    :
    : Thanks
    : C
    :
    ' ---------------------------------------------------------------------------------------------
    ' Subroutine: FNGetPath() Ver: devel Created: 11JUN05
    ' Input: N/A
    ' Output: Complete path with file name removed
    ' Module:
    ' Called by:
    ' Description: Accepts instance of Common Dialog Box, returns user-entered path or error number.
    ' Notes: 1) Either Show.Open or Show.Save could be used without any code changes. 2) Actually
    ' selecting a file name will not affect the result - the file name is always stripped off.
    ' Modification:
    '
    ' ---------------------------------------------------------------------------------------------
    Public Function FNGetPath(cdlObj As Object, Optional Title As String = "GET PATH", _
    Optional InitDir As String) As Variant

    Dim strPrompt As String
    Dim strTitle As String

    On Error GoTo ErrHandler
    cdlObj.cdlDialog.FileName = "(SELECT PATH - Do Not Change This Entry)" '
    cdlObj.cdlDialog.DialogTitle = Title
    cdlObj.cdlDialog.InitDir = InitDir
    cdlObj.cdlDialog.ShowOpen
    FNGetPath = Left$(cdlObj.cdlDialog.FileName, InStr(cdlObj.cdlDialog.FileName, cdlObj.cdlDialog.FileTitle) - 1)
    Exit Function

    ErrHandler:
    If Err.Number = cdlCancel Then
    FNGetPath = cdlCancel
    Else
    strTitle = "FNGetPath ERROR"
    strPrompt = "ERROR NUMBER: " & Err.Number & vbCrLf & "ERROR DESC: " & Err.Description & "."
    MsgBox strPrompt, vbOKOnly + vbExclamation, strTitle
    FNGetPath = Err.Number
    End If
    End Function ' FNGetPath()

    For testing, place an instance of the Common Dialog Control with the name property set to cdlDialog and a command button named cmdSetPath. In cmdSetPath's Click event place the following code:
    Private Sub cmdSetPath_Click()
    Dim strPath As String

    strPath = FNGetPath(Me, "GET TARGET PATH", "C:")
    If IsNumeric(strPath) Then GoTo HandleError
    Debug.Print strPath, IsNumeric(strPath)
    Exit Sub

    HandleError:
    Debug.Print "RETURNED ERROR: " & strPath
    Stop
    End Sub

    Hope this helps
    Ed
  • : How do I use the Common Dialog Control to return folder names - I don't want to have to select a file then draw the path name back off because I am setting a destination for saving / moving files ... a volume/file manger application

    If you don't mind having to create your form and manage it popping up, etc., then you might consider using the DirListBox control. Not as pretty as the common dialog control, but it gets the job done.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories