Viz Pilot User Guide
Version 8.1 | Published August 16, 2017 ©
Dialog Components
The following section describes standard Windows dialog boxes such as opening, saving and printing of files.
To use the dialog components they must be linked to a button or another function with VBscript. Some scripting examples follows below.
This section contains the following topics:
-
Open & Save Components
-
Font, Color, Print, PrintDisplay, Find and Replace Components
Open & Save Components
Open displays a file-selection dialog. Save displays a "Save As" dialog for saving files.
Notable Properties
-
DefaultExt: Specifies a default file extension.
-
FileName: Indicates the name and directory path of the last file selected.
-
InitialDir: Determines the current directory when the dialog opens.
Script Example
This is a Open and Save dialog example that opens a file reading the content into a multiline edit box. The template uses the OpenDialog and SaveDialog components. Note the settings of the Filter and Title properties in the Object Inspector. To invoke a dialog, call its .Execute method. Execute opens the file-selection dialog, returning True when the user selects a file and clicks Open or Save. If the user clicks Cancel, .Execute returns False.
const
ForReading =
1
const
ForWriting =
2
const
ForAppending =
8
\q OpenDialog example
Sub TWUniButton1Click(Sender)
if
OpenDialog1.Execute then
TWUniMemo1.Lines.LoadFromFile(OpenDialog1.Filename)
end
if
End sub
\q SaveDialog example
Sub TWUniButton2Click(Sender)
if
SaveDialog1.Execute then
TWUniMemo1.Lines.SaveToFile(SaveDialog1.Filename)
end
if
End sub
Further is an Open dialog example using the File System Object to read the content of the chosen file. Documentation on the File System Object can be found at: http://www.microsoft.com/scripting.
Sub TWUniButton3Click(Sender)
if
OpenDialog1.Execute then
Set fso = CreateObject(
"Scripting.FileSystemObject"
)
Set ts = fso.OpenTextFile(OpenDialog1.Filename, ForReading)
\q The file has been opened, now read the content
TWUniMemo1.Text = ts.ReadAll
\q Close the file
ts.close
\q Clean up
set ts = nothing
set fso = nothing
end
if
End sub
Font, Color, Print, PrintDisplay, Find and Replace Components
The Font, Color, Print, PrintDisplay, Find and Replace dialogs all displays generic Windows dialogs to do operations specific to their properties and methods.
Notable Properties
-
Color: Specifies the background color of the control.
-
Font.Name: Identifies the typeface of the font.
Script Example
The following script uses one button and executes the Font and Color dialog.
Sub TWUniButton1Click(Sender)
FontDialog1.Execute
TWUniButton1.Font.Name = FontDialog1.Font.Name
ColorDialog1.Execute
TWUniButton1.Color = ColorDialog1.Color
End sub
As with the Open and Save dialogs the Execute method is used. This small script enables the user to select and set the font and color for the button component.