8.4. Retrieve Values from the Custom Dialog Box

After displaying a custom dialog box for your user, your script must retrieve the values of the dialog controls. You retrieve these values by referencing the appropriate identifiers in the dialog record.

You'll find an example of how to retrieve values from a custom dialog box in the following subsection.


In the following sample script several of the techniques described earlier in this section have been used.

In this script, the array named ListBox1 is filled with three elements ("Apples", "Oranges", and "Pears"). The default value of TextBox1 is set to 12. A variable named response is used to store information about how the custom dialog box was closed. An identifier named ListBox1 is used to determine whether the user chose "Apples", "Oranges", or "Pears" in the list box named ListBox$. Finally, a Select Case . . . End Select statement is used to display a message box appropriate to the manner in which the user dismissed the dialog box.

Sub Main()
 Dim ListBox1$(2)     'Initialize list box array.
 Dim response%

 ListBox1$(0) = "Apples"
 ListBox1$(1) = "Oranges"
 ListBox1$(2) = "Pears"

 Begin Dialog UserDialog ,,163,94,"Grocery Order"
  Text 13,6,32,8,"&Quantity:",.Text1 'First control in
               'template gets the focus.
  TextBox 48,4,28,12,.TextBox1
  ListBox 12,28,68,32,ListBox1$,.ListBox1
  OKButton 112,8,40,14
  CancelButton 112,28,40,14
 End Dialog

 Dim b As UserDialog  'Create the dialog record.
 b.TextBox1 = "12"    'Set default value of the text box
          'to 1 dozen.
 response = Dialog(b)  'Display the dialog box.

 Select Case response%
  Case -1
   Fruit$ = ListBox1$(b.ListBox1)
   MsgBox "Thank you for ordering " + b.TextBox1 + " " + Fruit$ + "."

  Case 0
   MsgBox "Your order has been canceled."
 End Select
End Sub

More information

8. Use a custom dialog box in a script.