Please enable JavaScript to view this site.

A-Shell Reference

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:

ashref_img96

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 or perhaps organizing the checkboxes into an XTREE.

See Also

Get Control ID for an example scenario involving the need to query a radio button in order to enable/disable another control.