Microsoft KB Archive/80070

{|
 * width="100%"|

Evaluating Which Button Was Pressed in a User-Defined Dialog

 * }

Q80070

-

The information in this article applies to:


 * Microsoft Word for Windows, versions 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
 * Microsoft Word for Windows, version 7.0
 * Microsoft Word for the Macintosh, versions 6.0, 6.0.1

-

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 &quot;N&quot; 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, &quot;Example Macro&quot; PushButton 10, 6, 88, 21, &quot;Button-1&quot; PushButton 10, 30, 88, 21, &quot;Button-2&quot; PushButton 10, 54, 88, 21, &quot;Button-3&quot; 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(&quot;Ok was Pressed!&quot;, &quot;OK-Bottom&quot;, 64) Case 0 MsgBox(&quot;Cancel was Pressed!&quot;, &quot;Cancel-Bottom&quot;, 16) Case 1 MsgBox(&quot;Button-1 was Pressed!&quot;, &quot;PushBottom-1&quot;, 64) Case 2 MsgBox(&quot;Button-2 was Pressed!&quot;, &quot;PushBottom-2&quot;, 64) Case 3 MsgBox(&quot;Button-3 was Pressed!&quot;, &quot;PushBottom-3&quot;, 64) Case Else Goto Bye End Select Bye: End Sub                                'End of Macro For more information, search for &quot;WordBasic Programming Language&quot; and &quot;Dialog&quot; using the Help menu.

Additional query words: pushbutton dialog winword2 word6 6.0.1 word7 winword 7.0 word95 push button 2.0 macword

Keywords : kbmacro

Issue type :

Technology :