Setting and Evaluating Values for a Dialog CheckBox

ID: Q87111

The information in this article applies to:

SUMMARY

User-defined dialog boxes created in the Microsoft Word for Windows macro language, can include check boxes that are marked, unmarked, or unavailable (dimmed). To set the default value for a check box, set the CheckBox dialog argument to one of the following values:

  0   Clear the check box
  1   Place an X in the check box
 -1   Make the check box unavailable (dimmed)

These values are also returned to indicate the status of the check box. For example, if the user marks a check box, the value "1" is returned to indicate that the box was selected (marked).

To check the return value for a CheckBox statement, add a command similar to the following just below the Dialog statement:

   x = Dlg.CheckBox1

   Dlg = the dialog box array
   CheckBox1 = dialog box field name

If the "x" variable evaluates to be "1", CheckBox1 in the UserDialog was selected.

The following macro evaluates CheckBox1 in the UserDialog dialog record:

 Sub MAIN
   Begin Dialog UserDialog 320, 120
      OKButton 210, 56, 88, 22
      CancelButton 211, 83, 88, 21
      CheckBox 35, 24, 196, 17, "Check Box", .CheckBox1
   End Dialog
   Dim dlg As UserDialog
   n = Dialog(dlg)
   x = dlg.checkbox1                  'assign status of Checkbox1 to x
   If x = 1 Then MsgBox "Checkbox was checked"
 End Sub

MORE INFORMATION

In addition to evaluating check boxes, CheckBox statements can be set to default values. The following macro fills CheckBox1 with gray in the UserDialog dialog record:

 Sub MAIN
   Begin Dialog UserDialog 320, 120
      OKButton 210, 56, 88, 22
      CancelButton 211, 83, 88, 21
      CheckBox 35, 24, 196, 17, "Greyed Check Box", .CheckBox1
      CheckBox 35, 42, 111, 16, "Check Box", .CheckBox2
   End Dialog
   Dim dlg As UserDialog
   dlg.CheckBox1 = - 1                'Sets CheckBox1 to gray
   n = Dialog(dlg)
 End Sub

The default display for a CheckBox statement is clear (no check mark).

Word 6.0 for Windows

In order to actually disable an item in a dialog, use the DlgEnable statement within a dialog function. DlgEnable allows you to enable or disable the dialog box control identified by Identifier[$] while the dialog box is displayed. When a dialog box control is disabled, it is visible in the dialog box, but is dimmed and not functional.

For information about using a dialog function, see the "Creating Dynamic Dialog Boxes" topic in the Online Help file for Word 6.0 for Windows.

REFERENCES

"Using WordBasic," by WexTech Systems and Microsoft, page 162

Additional query words: word basic

Keywords          : kbmacro winword macword word6 winword2 word7 word95 
Version           : WINDOWS: 6.0, 6.0a, 6.0c, 7.0, 7.0a; MACINTOSH 6.0, 6.0.1
Platform          : MACINTOSH WINDOWS

Last Reviewed: November 18, 1997