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
| Property | Type | Description |
|---|---|---|
DialogTitle | String | Dialog title |
InitialDir | String | Initial directory |
DefaultExt | String | Default extension |
FileName | String | Default/return filename |
Filter | String | File filter |
MultiSelect | Boolean | Allow multiple selection (default False) |
OverwritePrompt | Boolean | Overwrite prompt (default True) |
PathMustExist | Boolean | Path must exist (default True) |
FileMustExist | Boolean | File must exist (default True) |
HideReadOnly | Boolean | Hide read-only option (default True) |
Methods
ShowOpen
Show open file dialog
vb
Public Function ShowOpen() As VariantReturns: 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 WithShowSave
Show save file dialog
vb
Public Function ShowSave() As StringReturns: 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 WithShowBrowseForFolder
Show folder browse dialog
vb
Public Function ShowBrowseForFolder() As StringReturns: 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 WithSelectFiles
Select multiple files and return collection
vb
Public Function SelectFiles() As cCollectionReturns: 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 WithComprehensive 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 SubExample 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 SubExample 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 SubBest Practices
- Set Initial Directory: Use App.Path or user's last selected directory
- File Filtering: Provide reasonable file type filter options
- Error Handling: Check if return value is empty/Empty
- User Experience: Set meaningful dialog titles