The information in this article applies to:
SUMMARY
Microsoft Word for Windows includes the Dialog Editor program, which you
can use to create custom dialog boxes for use in Word for Windows WordBasic
macros. You can use custom dialog boxes to obtain user input using common
dialog box controls, such as buttons, check boxes, list boxes, combo boxes,
and option buttons.
MORE INFORMATION
Below are examples of macros that demonstrate how to set default
values for and how to get information out of each dialog box item.
Each macro example isolates and demonstrates a single item's use.
Working with Check BoxesThe following macros display a dialog box with an OK button and a check box. The check box will be selected as the default. When the OK button is chosen a message box will be displayed indicating whether the check box is selected or not.Word 2.x, 6.x
A check box has only 2 states: selected or not selected. The value 1
indicates that the check box is selected and 0 indicates that the box
is not selected. If no default value is specified, the check box comes
up not selected. The .checkbox1 field (defined in the dialog box
definition) will be set to either 1 or 0 indicating whether it is
selected.
Word 1.xUse the same macro as above, but change the "Begin Dialog" line to read:
Working with Option ButtonsThe following macros display a dialog box with an OK button and an option group containing three option buttons. The third button will be selected as the default button. When the OK button is chosen, a message box will display, indicating which option button was selected.Word 2.x, 6.x
Only one option button at a time can be selected in an option group.
Each button has a number assigned to it. The first button is always 0,
the second is 1, the third is 2, etc. If no default value is
specified, the first option button is chosen (having the value 0). The
.OptionGroup1 field (defined in the dialog box definition) will be set to
the number indicating which button is chosen.
Word 1.xUse the macro above, but change the "Begin Dialog" line to read:
Working with Text BoxesThe following macro displays a dialog box with an OK button and a text box. The word "Hello!" will be displayed as the default text. When the OK button is chosen, a message box will display the text that appeared in the text box when the button was chosen.Word 2.x, 6.x
Text boxes store text strings. If no default string is specified, the
text box will be empty. The .TextBox1 field (defined in the dialog box
definition) will be set to a string indicating what is contained in
the text box.
Word 1.xUse the same macro as above, but change the "Begin Dialog" line to read:
Working with List BoxesThe following macro displays a dialog box with an OK button and a list box that contains a list of different types of fruits. Bananas will be selected as the default fruit. When the OK button is chosen, a message box will display the selected item from the list box.Word 2.x, 6.x
The information that displays in a list box comes from an array. In
the example above, the array Fruits$() is created and filled with a
list of fruits. Notice that Fruits$() appears in the ListBox line of
the dialog box definition, indicating that it will list values found
in this array.
The selected item in a list box is a number indicating which item in the array was picked. The first item is 0, the second is 1, the third 2, and so on. If you don't want any item to be selected in the listbox, set the default value to -1. The .ListBox1 field (defined in the dialog box definition) will be set to a number indicating which item was selected. This number directly corresponds to an item in the specified array and can be used to index the array (as demonstrated in the last MsgBox line). Word 1.xUse the same macro as above, but change the "Begin Dialog" line to read:
Working with Combo BoxesThe following macro displays a dialog box with an OK button and a combo box that contains a list of different types of fruits. Grapes will be selected as the default fruit (although it doesn't appear in the list). The user can select a fruit or type something unique in the text box part of the combo box. When the OK button is chosen a message box will display the item or text selected in the combo box.Word 2.x, 6.x
The information that is displayed in a combo box comes from an array.
In the example above the array Fruits$() is created and filled with a
list of fruits. Note that Fruits$() appears in the Combobox line of
the dialog box definition, indicating that it will list values found
in this array.
The selected item in a combo box is a text string value equivalent to the item found in the list. This differs from a list box which uses a numeric value that indexes the filling array. The reason for this difference is that the user can type in the text box portion of the combo box a value different from any value found in the list. The combo box is more like a text box, but provides a list of values that can be chosen to conveniently use. If no default value is specified, the combo box displays with no item selected, and the text box portion of the combo box is empty. If you don't want any item to be selected in the listbox set the default value to -1. The .ComboBox1 field (defined in the dialog box definition) will be set to a string indicating what is contained in the text box part of the combo box. Word 1.xUse the same macro as above, but change the "Begin Dialog" line to read:
Working with OK, Cancel, and Command (Push) ButtonsThe following macro displays a dialog box with an OK, Cancel, and three other push buttons. When a button is chosen, a message box will display, indicating which button was chosen.Word 2.x, 6.x
The functional form of the Dialog command returns a value indicating
which button was chosen in the dialog box. The OK button is always -1,
and the Cancel button is always 0. The number assigned to a command
button is determined by the order in which the PushButton statement
appears in the dialog box definition. The first command (push) button
will be 1, the second 2, the third 3, and so on.
The functional form of the Dialog command is not required when using buttons. The Dialog line above could read Dialog dlg(as the other examples illustrate) and still function correctly. However, there would be no way of determining which button was chosen. There is a way to set which button will be the default button selected when the ENTER key is chosen. This is implemented as an optional parameter to the Dialog command and is not documented. For more information on setting the default button in a dialog box, query on the following words in the Microsoft Knowledge Base: Defaultbutton and custom and Dialog and Word 1.x
Note: Versions 1.0, 1.1, and 1.1a of Word for Windows do not support
the use of command buttons and the function format of the Dialog
command. If the OK button is chosen, the macro will run uninterrupted.
If the Cancel button is chosen, Word will generate an error that can
be trapped with the On Error message. In the example above, Word will
jump to the CancelPressed command if the Cancel button is chosen.
Reference(s): "Microsoft Word for Windows User's Guide," version 2.0, pages 787-792 "Microsoft Using WordBASIC," version 2.0, pages 68-80 "Microsoft WordBASIC Macro Developers Kit," version 2.0, pages 74-96 Additional query words: 1.x 1.10a 2.0 winword2 winword 6.0 properties property controls control list check combo dropdown macrode.exe checkbox listbox textbox drop down pushbutton highlight
Keywords : |
Last Reviewed: September 30, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |