Skip to content

VBMAN.Dialog - File Dialog Object

Overview

VBMAN.Dialog provides Windows standard file dialog functionality, including opening files, saving files, selecting folders, etc.

Core Features

  • Open File Dialog: Supports single/multi selection, file filtering
  • Save File Dialog: Supports overwrite prompt, default extension
  • Folder Browse Dialog: Supports new dialog style
  • Property Configuration: Set dialog options through properties

Properties

PropertyTypeDescription
DialogTitleStringDialog title
InitialDirStringInitial directory
DefaultExtStringDefault extension
FileNameStringDefault/return filename
FilterStringFile filter
MultiSelectBooleanAllow multiple selection (default False)
OverwritePromptBooleanOverwrite prompt (default True)
PathMustExistBooleanPath must exist (default True)
FileMustExistBooleanFile must exist (default True)
HideReadOnlyBooleanHide read-only option (default True)

Methods

ShowOpen

Show open file dialog

vb
Public Function ShowOpen() As Variant

Returns: Selected file path, returns Empty if cancelled

Example:

vb
With VBMAN.Dialog
    .DialogTitle = "Select File"
    .InitialDir = "C:\\"
    .Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
    .FileName = ""
    
    Dim result As Variant
    result = .ShowOpen
    
    If Not IsEmpty(result) Then
        MsgBox "Selected: " & result
    End If
End With

ShowSave

Show save file dialog

vb
Public Function ShowSave() As String

Returns: Saved file path, returns empty string if cancelled

Example:

vb
With VBMAN.Dialog
    .DialogTitle = "Save File"
    .InitialDir = App.Path
    .DefaultExt = "txt"
    .Filter = "Text Files (*.txt)|*.txt"
    .FileName = "New File.txt"
    
    Dim savePath As String
    savePath = .ShowSave
    
    If savePath <> "" Then
        ' Save file...
    End If
End With

ShowBrowseForFolder

Show folder browse dialog

vb
Public Function ShowBrowseForFolder() As String

Returns: Selected folder path, returns empty string if cancelled

Example:

vb
With VBMAN.Dialog
    .DialogTitle = "Select Folder"
    
    Dim folderPath As String
    folderPath = .ShowBrowseForFolder
    
    If folderPath <> "" Then
        MsgBox "Selected: " & folderPath
    End If
End With

SelectFiles

Select multiple files and return collection

vb
Public Function SelectFiles() As cCollection

Returns: Collection of selected file paths

Example:

vb
With VBMAN.Dialog
    .DialogTitle = "Select Multiple Files"
    .MultiSelect = True
    .Filter = "All Files (*.*)|*.*"
    
    Dim files As cCollection
    Set files = .SelectFiles
    
    Dim i As Long
    For i = 1 To files.Count
        Debug.Print files(i)
    Next i
End With

Comprehensive Examples

Example 1: Open Text File

vb
Private Sub OpenTextFile()
    With VBMAN.Dialog
        .DialogTitle = "Open Text File"
        .InitialDir = App.Path
        .Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
        .FileMustExist = True
        
        Dim filePath As Variant
        filePath = .ShowOpen
        
        If Not IsEmpty(filePath) Then
            Dim content As String
            content = VBMAN.ToolsStream.LoadFileAsText(CStr(filePath))
            Text1.Text = content
        End If
    End With
End Sub

Example 2: Save Configuration

vb
Private Sub SaveConfig()
    With VBMAN.Dialog
        .DialogTitle = "Save Configuration"
        .InitialDir = App.Path
        .DefaultExt = "ini"
        .Filter = "Configuration Files (*.ini)|*.ini"
        .OverwritePrompt = True
        .FileName = "config.ini"
        
        Dim savePath As String
        savePath = .ShowSave
        
        If savePath <> "" Then
            VBMAN.Ini.SaveTo savePath
        End If
    End With
End Sub

Example 3: Select Output Directory

vb
Private Sub SelectOutputDir()
    With VBMAN.Dialog
        .DialogTitle = "Select Output Directory"
        .InitialDir = "C:\\"
        
        Dim outputDir As String
        outputDir = .ShowBrowseForFolder
        
        If outputDir <> "" Then
            LabelOutput.Caption = outputDir
        End If
    End With
End Sub

Best Practices

  1. Set Initial Directory: Use App.Path or user's last selected directory
  2. File Filtering: Provide reasonable file type filter options
  3. Error Handling: Check if return value is empty/Empty
  4. User Experience: Set meaningful dialog titles

VB6 and LOGO copyright of Microsoft Corporation