Viz Pilot User Guide
Version 8.6 | Published October 23, 2020 ©
Dialog Components
The following section describes standard Windows dialog boxes such as opening, saving and printing files.
To use the dialog components, they must be linked to a button or another function with VBscript. Some scripting examples follow below.
This section contains the following topics:
Open and 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
The example below shows an Open and Save dialog 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 subThe example below shows an Open dialog using the File System Object to read the content of the chosen file. Documentation about 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 subFont, Color, Print, PrintDisplay, Find and Replace Components
The Font, Color, Print, PrintDisplay, Find and Replace dialogs all display generic Windows dialogs for performing 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 subAs with the Open and Save dialogs, the Execute method is used above. This small script lets you select and set the font and color for the button component.