~~Title: Simple Dialogs ~~
With the simple method, the script is not responsible for the dialog’s message loop. Instead, the script prepares a **[[:reference:scripting_reference:scripting_objects:dialog|Dialog]]** object, and invokes the **Show** method to display the dialog. The **Show** method doesn’t return until the user has closed the dialog, at which time you can read the values of any controls on the dialog to find out what data the user provided.
To allow the user to close the dialog you should add one or more //Button// controls with the **Close Dialog** property set to **True**. The return value of the **Show** method will be the value you specified for the button’s **Return Value** property.
Below is an example of a script that displays a dialog using the simple method. The raw XML for the dialog is also included. If you want to experiment with this example, create a new toolbar button, and paste the script code into the **Script Code** tab of the command editor, and the resources XML into the **Resources** tab. All the following examples are written in VBScript.
==Script Code - VBScript==
Function OnClick(ByRef clickData)
Set Dlg = DOpus.Dlg
Dlg.window = clickData.func.sourcetab
Dlg.template = "testdlg"
retVal = Dlg.Show
DOpus.Output "Return code = " & retVal
End Function
==Script Code - JScript==
function OnClick(clickData) {
var Dlg = DOpus.Dlg;
Dlg.window = clickData.func.sourcetab;
Dlg.template = "testdlg";
var retVal = Dlg.Show();
DOpus.Output("Return code = " + retVal);
}
==Resources==
This script creates and displays the following dialog:
{{:media:image134.png?nolink|}}
In the script, the **[[:reference:scripting_reference:scripting_objects:dialog|Dialog]].Show** method is called on the //Dlg// object, and its return value (//retVal//) corresponds to the button you click in the dialog. The value is then printed to the script output log.
When the **Show** method returns your script can read the value of any controls it may have added to the dialog – see the //[[..:reading_dialog_control_values|Reading Dialog Control Values]]// page for an example of this.