Evaluating Which Button Was Pressed in a User-Defined Dialog

ID: Q80070

The information in this article applies to:

SUMMARY

The following Microsoft WordBasic macro provides an example of how to evaluate which button was pressed in a user-defined dialog box. The macro uses a Select Case structure to evaluate the value returned by the dialog function; N = Dialog(DialogRecord).

MORE INFORMATION

Specific values are assigned to the buttons in a dialog box. The function N=Dialog(DialogRecord) stores the value assigned to the button in the dialog box for later use. (DialogRecord) is the name that the user gives to the dialog box. The values of "N" are as follows:

Button Type        N=Dialog(DialogRecord)       Value Assigned
-----------        ----------------------       --------------

OK button              -1                       Always
Cancel button           0                       Always
Pushbutton-1            1                       According to order
Pushbutton-2            2                       According to order
Pushbutton-3            3                       According to order
Pushbutton-M            M                       According to order

The values for the pushbuttons are chronologically assigned, meaning the first pushbutton is assigned one, the second two, and so on. The OK button always has the value minus one (-1) and the Cancel button always has the value zero (0).

The following macro demonstrates how the evaluation works. Inside the case statements various types of tasks can be performed. This example uses message boxes for simplicity.

 Sub MAIN                                'Macro Starts Here
 Begin Dialog UserDialog 320, 98, "Example Macro"
        PushButton 10, 6, 88, 21, "Button-1"
        PushButton 10, 30, 88, 21, "Button-2"
        PushButton 10, 54, 88, 21, "Button-3"
        OKButton 165, 18, 88, 21
        CancelButton 166, 46, 88, 21
 End Dialog
 Dim MyDlg As Dialog UserDialog   'Mydlg came be change to anything
 N = Dialog(MyDlg)
 Select Case N
        Case - 1
                MsgBox("Ok was Pressed!", "OK-Bottom", 64)
        Case 0
                MsgBox("Cancel was Pressed!", "Cancel-Bottom", 16)
        Case 1
                MsgBox("Button-1 was Pressed!", "PushBottom-1", 64)
        Case 2
                MsgBox("Button-2 was Pressed!", "PushBottom-2", 64)
        Case 3
                MsgBox("Button-3 was Pressed!", "PushBottom-3", 64)
        Case Else
                Goto Bye
        End Select
 Bye:
 End Sub                                 'End of Macro

For more information, search for "WordBasic Programming Language" and "Dialog" using the Help menu.

Kbcategory: kbusage kbmacro KBSubcategory: Additional query words: pushbutton dialog winword2 word6 6.0.1 word7 winword 7.0 word95 push button 2.0 2.0a 2.0a-CD 2.0b 2.0c macword

Keywords          : kbmacro
Version           : 2.x 6.0 6.0a 6.0c 7.0 | 6.
Platform          : MACINTOSH WINDOWS

Last Reviewed: February 9, 1998