DlgControlId()

Syntax

DlgControlId(Identifier$)

Remarks

Used within a dialog function to return the numeric identifier for the dialog box control specified by Identifier$, the string identifier of the dialog box control. Numeric identifiers are numbers, starting at 0 (zero), that correspond to the positions of dialog box control instructions within a dialog box definition. For example, consider the following instruction in a dialog box definition:


CheckBox 97, 54, 36, 12, "&Update", .MyCheckBox

The instruction DlgControlId("MyCheckBox") returns 0 (zero) if the CheckBox instruction is the first instruction in the dialog box definition, 1 if it is the second instruction, and so on.

In most cases, your dialog functions will perform actions based on the string identifier of the control that was selected. However, dialog functions can use numeric identifiers to manipulate more quickly a large number of controls (for example, the number of controls found in a multiple-panel dialog box). Note that if you change the order of instructions in a dialog box definition, the numeric identifiers for the corresponding controls will change also.

For information about using a dialog function, see Chapter 5, "Working with Custom Dialog Boxes," in Part 1, "Learning WordBasic."

Example

This macro displays a simple dialog box containing the OK and Cancel buttons and a check box labeled "Test." The dialog function checks to see if the value for action is 2, meaning a control has been selected or chosen. If so, the dialog function then checks to see if the control selected is the first one defined—in other words, if the numeric identifier returned by DlgControlId() is 0 (zero). If it is, a message box is displayed in front of the dialog box, which remains on-screen.


Sub MAIN
Begin Dialog UserDialog 320, 50, "Test", .MyDlgFunction
    CheckBox 212, 10, 88, 19, "Test", .Test            '0
    OKButton 7, 10, 88, 21                            '1
    CancelButton 109, 10, 88, 21                        '2
End Dialog
Dim dlg As UserDialog
DisableInput 1
button = Dialog(dlg)
DisableInput 0
End Sub

END BREAK


Function MyDlgFunction(identifier$, action, suppvalue)
If action = 2 Then
    If DlgControlId(identifier$) = 0 Then
        MsgBox "You selected the first control " + \
                "defined in the dialog box definition."
    End If
End If
End Function

See Also

DlgFocus, DlgValue