# Query Checkbox > [HTML Version](querycheckbox.htm) CTLOP\_QRYCB (opcode 5) may be used to query the current value of a checkbox or radiobutton. The value (returned in the _cstatus_ parameter) may be one of: 0 (unchecked), 1 (checked), or 2 (indeterminate, for MBF\_3STATE checkboxes). The ability to query the value of a checkbox is useful when you want to present a bunch of checkboxes and let the user click on them in any order, or TAB around them, without having to code the INFLD logic necessary for handling individual field exitcodes and immediate validation. Instead, you can just let EVENTWAIT handle the operation until the user triggers the event requiring that you retrieve the values. Note that in the local A-Shell/Windows environment, a special operation to query a checkbox isn't really necessary, since the AUI system will automatically and immediately update the checkbox value variable (specified in the _func_ parameter when the checkbox was created). But in the ATE environment (where the checkbox is on the client and the variable is on the server), direct updating of the value variable isn't possible. The CTLOP\_QRYCB method described below, will work in all environments and thus is recommended. As an example, consider the following simple dialog containing several checkbox options: (./images/ashref_img96.png) The program creates the dialog, then waits in an EVENTWAIT loop to either click the green button (which triggers the checkbox query routine and displays the results in the trace window), or to close the dialog (by clicking the red X or hitting ESC). **Source code for above dialog.** program qrycb,1.0(100) \! simple example of querying checkboxes \++include ashinc:ashell.def define MAX\_CB = 7 \! number of checkboxes define DLG\_ID\$ = "dlg1" \! id of main dialog map1 cb(MAX\_CB) map2 cb'id\$,s,20 \! control id map2 cb'dsc\$,s,20 \! display text map2 cb'val,b,1 \! checkbox value map1 misc map2 i,f map2 row,b,4 map2 col,b,4 map2 evw'parentid\$,s,24 map2 evw'ctlid\$,s,24 map2 evw'flags,b,4 map2 exitcode,f map2 status,f data "cbAPEX", "APEX" data "cbASQL", "ASQL" data "cbATE", "ATE" data "cbATS", "ATS" data "cbISAMA", "ISAM-A" data "cbPDFX", "PDFX" data "cbPolyShell", "PolyShell" \! create the dialog xcall AUI, AUI\_CONTROL, CTLOP\_ADD, DLG\_ID\$, "A-Shell Options", \& MBST\_ENABLE, MBF\_DIALOG + MBF\_ALTPOS + MBF\_SYSMENU, \& NUL\_CMD\$, NUL\_FUNC\$, NUL\_CSTATUS, 2000, 5000, 8000, 25000 \! create the checkbox controls for i = 1 to 7 read cb'id\$(i), cb'dsc\$(i) \! divide into two columns if i <= 4 then row = (i + 1) \* 1000 \! millirows col = 3000 else row = (i - 3) \* 1000 col = 12000 endif cb'val(2) = 1 \! (initialize one of the checkboxes to checked) xcall AUI, AUI\_CONTROL, CTLOP\_ADD, cb'id\$(i), cb'dsc\$(i), \& MBST\_ENABLE, MBF\_CHKBOX + MBF\_LFJUST + MBF\_TABSTOP, \& NUL\_CMD\$, cb'val(i), NUL\_CSTATUS, row, col, row+1000, col+7000, \& NUL\_FGC, NUL\_BGC, NUL\_FONTATTR, NUL\_FONTSCALE, NUL\_FONTFACE\$, \& NUL\_TOOLTIP\$, DLG\_ID\$ next i \! create qry/exit buttons xcall AUI, AUI\_CONTROL, CTLOP\_ADD, "btnQry", "checks::ashico1", \& MBST\_ENABLE, MBF\_BUTTON + MBF\_ICON + MBF\_KBD, \& "VK\_xF101", NUL\_FUNC\$, NUL\_CSTATUS, 5500, 14000, 6500, 16000, \& NUL\_FGC, NUL\_BGC, NUL\_FONTATTR, NUL\_FONTSCALE, NUL\_FONTFACE\$, \& "Query the current checkbox values", DLG\_ID\$ xcall AUI, AUI\_CONTROL, CTLOP\_ADD, "btnExit", "delete::ashico1", \& MBST\_ENABLE, MBF\_BUTTON + MBF\_ICON + MBF\_KBD, \& "VK\_ESC", NUL\_FUNC\$, NUL\_CSTATUS, 5500, 17000, 6500, 19000, \& NUL\_FGC, NUL\_BGC, NUL\_FONTATTR, NUL\_FONTSCALE, NUL\_FONTFACE\$, \& "Exit dialog", DLG\_ID\$ \! wait for user to click Query or Exit evw'parentid\$ = "dlg1" evw'ctlid\$ = cb'id\$(1) evw'flags = 0 do xcall AUI, AUI\_EVENTWAIT, evw'parentid\$, evw'ctlid\$, exitcode, evw'flags switch exitcode case -101 \! clicked ok trace.print "Querying checkboxes..." for i = 1 to MAX\_CB xcall AUI, AUI\_CONTROL, CTLOP\_QRYCB, cb'id\$(i), NUL\_CTEXT\$, \& NUL\_CSTATE, NUL\_CTYPE, NUL\_CMD\$, NUL\_FUNC\$, status cb'val(i) = status trace.print "CB #"+i+" : "+cb'dsc\$(i)+" = "+cb'val(i) next i exit endswitch loop until exitcode = 1 \! (escape) xcall AUI, AUI\_CONTROL, CTLOP\_DEL, DLG\_ID\$ \! close dialog end **Comments** The program above uses alphanumeric IDs for the checkbox controls, which eliminates the need for the CTLOP\_ADD operation to return the numeric ID of each newly-created checkbox. This speeds up creation of the dialog in the ATE environment (where otherwise the server would have to wait for the return status of each checkbox before creating the next one). But it doesn't help the CTLOP\_QRYCB operation, which would require a round-trip (server to client and back) for each checkbox queried. For a small dialog like this it wouldn't be an issue, but if you have a dialog with hundreds of checkboxes, you may want to consider optimizing the ATE performance either using [Batch Operations](batchoperations.htm.md) or perhaps organizing the checkboxes into an XTREE. **See Also** [Get Control ID](get_control_id.htm.md) for an example scenario involving the need to query a radio button in order to enable/disable another control.