Dialog (function)

<< Click to Display Table of Contents >>

Dialog (function)

Dialog(Dlg)

Displays a custom dialog box.

Dlg is the name of a dialog variable that must have been declared previously with the Dim statement.

The return value is the index of the button that was pressed by the user:

-1OK
0Cancel
> 0User-defined command buttons (1 for the first, 2 for the second, etc.)

See also: DlgEnable, DlgText, DlgVisible, section Dialog boxes

Example:

' Shows different information, depending on

' which button was pressed.

Sub Main

 Dim MyList$(2)

 MyList(0) = "Banana"

 MyList(1) = "Orange"

 MyList(2) = "Apple"

 Begin Dialog DialogName1 60, 60, 240, 184, "Test Dialog"

         Text 10, 10, 28, 12, "Name:"

         TextBox 40, 10,50, 12, .joe

         ListBox 102, 10, 108, 16, MyList$(), .MyList1

         ComboBox 42, 30, 108, 42, MyList$(), .Combo1

         DropListBox 42, 76, 108, 36, MyList$(), .DropList1$

         OptionGroup .grp1

                 OptionButton 42, 100, 48, 12, "Option&1"

                 OptionButton 42, 110, 48, 12, "Option&2"

         OptionGroup .grp2

                 OptionButton 42, 136, 48, 12, "Option&3"

                 OptionButton 42, 146, 48, 12, "Option&4"

         GroupBox 132, 125, 70, 36, "Group"

         CheckBox 142, 100, 48, 12, "Check&A", .Check1

         CheckBox 142, 110, 48, 12, "Check&B", .Check2

         CheckBox 142, 136, 48, 12, "Check&C", .Check3

         CheckBox 142, 146, 48, 12, "Check&D", .Check4

         CancelButton 42, 168, 40, 12

         OKButton 90, 168, 40, 12

         PushButton 140, 168, 40, 12, "Button1"

         PushButton 190, 168, 40, 12, "Button2"

 End Dialog

 Dim Dlg1 As DialogName1

 Dlg1.joe  = "Hare"

 Dlg1.MyList1 = 1

 Dlg1.Combo1 = "Kiwi"

 Dlg1.DropList1 = 2

 Dlg1.grp2 = 1

 ' Dialog returns -1 for OK, 0 for Cancel, # for Button1/2

 button = Dialog(Dlg1)

 If button = 0 Then Return

 MsgBox "Input box: "& Dlg1.joe

 MsgBox "List box: " & Dlg1.MyList1

 MsgBox Dlg1.Combo1

 MsgBox Dlg1.DropList1

 MsgBox "Group1: " & Dlg1.grp1

 MsgBox "Group2: " & Dlg1.grp2

 Begin Dialog DialogName2 60, 60, 160, 60, "Test Dialog 2"

         Text 10, 10, 28, 12, "Name:"

         TextBox 42, 10, 108, 12, .fred

         OkButton 42, 44, 40, 12

 End Dialog

 If button = 2 Then

         Dim Dlg2 As DialogName2

         Dialog Dlg2

         MsgBox Dlg2.fred

 ElseIf button = 1 Then

         Dialog Dlg1

         MsgBox Dlg1.Combo1

 End If

End Sub