Progress
Programming
Handbook


Toggle Boxes

A toggle box, sometimes called a check box, represents a logical value. The presence (true) or absence (false) of filling in the toggle box indicates the current value. In a graphical interface, a toggle box and its filling style take on the native look of the windowing system. You can change a toggle value by positioning to it and pressing SPACEBAR. In a graphical interface, you can point to the box and click the mouse SELECT button.

In a character interface, a toggle box is represented by a pair of square brackets ([ ]) that are either empty (False) or contain an X (True).

Note that setting the FORMAT option or attribute does not affect the the toggle box widget. You see the effects of the FORMAT change only if you display the value as a fill-in or text.

The following form of the VIEW–AS phrase defines a toggle box:

SYNTAX
VIEW-AS TOGGLE-BOX [ size-phrase ] [ TOOLTIP tooltip ] 

There are no required options to use with the VIEW–AS phrase when defining a toggle box. You can optionally specify a label for the toggle box. Specify the label as a quoted character string.

If you do not use the LABEL option, the field or variable name is used. For an array, the default label includes the subscript in brackets ([ ]).

The following example, p-tbox.p, uses toggle boxes to represent an array of extent 3:

p-tbox.p
DEFINE VARIABLE choices   AS LOGICAL EXTENT 3
                          LABEL "Name", "Address", "Other"
                          INITIAL [yes, yes, no]
                          VIEW-AS TOGGLE-BOX. 
DEFINE VARIABLE curcust AS INTEGER.

FORM
    curcust LABEL "Customer Number" SKIP
    "Information to Show:" SKIP
    choices SKIP
    WITH SIDE-LABELS FRAME choice-frame TITLE "Show Customer Information".
    
FORM
    customer.name
    WITH FRAME name-frame NO-LABELS TITLE "Customer Name".FORM
    customer.address SKIP customer.address2 SKIP
    customer.city customer.state SKIP
    customer.country customer.postal-code
    WITH FRAME addr-frame NO-LABELS USE-TEXT TITLE "Customer Address".

FORM
    customer
    EXCEPT name cust-num address address2 city state country postal-code
    WITH FRAME oth-frame SIDE-LABELS USE-TEXT TITLE "Other Customer Data". 
ON GO OF FRAME choice-frame OR RETURN OF curcust
    DO:  
        HIDE FRAME name-frame FRAME addr-frame FRAME oth-frame.
          
        FIND  customer WHERE cust-num = INPUT curcust NO-ERROR.
        IF AMBIGUOUS customer OR NOT AVAILABLE customer
        THEN RETURN NO-APPLY.

        IF INPUT choices[1] /* name */
        THEN DISPLAY customer.name WITH FRAME name-frame.
        IF INPUT choices[2] /* address */
        THEN DISPLAY customer.address customer.address2
                     customer.city customer.state country postal-code
             WITH FRAME addr-frame.
        IF INPUT choices[3] /* other */
        THEN DISPLAY customer EXCEPT name cust-num address
                     address2 city state country postal-code
             WITH FRAME oth-frame.
        RETURN NO-APPLY.
    END.

DISPLAY choices WITH FRAME choice-frame.
ENABLE ALL WITH FRAME choice-frame.
STATUS INPUT "Enter customer number and GO.".

WAIT-FOR WINDOW-CLOSE OF CURRENT-WINDOW. 

When you run the example, you are prompted for a customer number. You can also set the three toggle boxes labeled cust–num, address, and other. You can set the toggle boxes to choose what information to display about the customer. When you press GO, the trigger finds the customer record and displays the information you specified.

For example, if you accept the default values for choices and press GO, the screen appears as follows:

In p-tbox.p, changing the value of a toggle box has no immediate effect. The toggle boxes are used to set a state that is then read when you press GO. By writing a trigger for the the VALUE–CHANGED event, you can also use a toggle box to trigger an immediate action.

The following example, p-tbox2.p, displays three toggle boxes that specify search criteria for customers. It displays the number of customers that meet the current criteria. Each time you change the value of a toggle box, the procedure recalculates the number of customers that meet the specified criteria.

p-tbox2.p
DEFINE VARIABLE cnt AS INTEGER FORMAT ">>9".
DEFINE VARIABLE must-have-balance AS LOGICAL INITIAL no
        VIEW-AS TOGGLE-BOX LABEL "Only if Balance Due".
DEFINE VARIABLE must-be-local AS LOGICAL INITIAL no
        VIEW-AS TOGGLE-BOX LABEL "Only if in Local Country".
DEFINE VARIABLE must-get-discount AS LOGICAL INITIAL no
        VIEW-AS TOGGLE-BOX LABEL "Only if Discount".
DEFINE VARIABLE local-country AS CHARACTER INITIAL "USA".

FORM 
   must-have-balance SKIP
   must-be-local SKIP
   must-get-discount SKIP(1)
   "There are" cnt "customers that meet these criteria."
   WITH FRAME count-frame TITLE "Counting Customers" NO-LABELS.

ON VALUE-CHANGED OF must-have-balance, must-be-local, must-get-discount
   DO:
     DEFINE VARIABLE meets-criteria AS LOGICAL.
     cnt = 0.
     FOR EACH customer:
         meets-criteria = yes.
         IF INPUT must-have-balance AND customer.balance <= 0 
         THEN meets-criteria = no.
         ELSE IF INPUT must-be-local AND customer.country <> local-country
         THEN meets-criteria = no.
         ELSE IF INPUT must-get-discount AND customer.discount = 0 
         THEN meets-criteria = no.

         IF meets-criteria 
         THEN cnt = cnt + 1.
     END.
     DISPLAY cnt WITH FRAME count-frame.
   END.

cnt = 0.
FOR EACH customer:
    cnt = cnt + 1.
END.

DISPLAY must-have-balance must-be-local must-get-discount cnt 
        WITH FRAME count-frame.
ENABLE must-have-balance must-be-local must-get-discount  
       WITH FRAME count-frame.

WAIT-FOR WINDOW-CLOSE OF CURRENT-WINDOW. 

The VALUE–CHANGED event occurs every time you alter the value of a toggle box. In
p-tbox2.p, each time you change the value of one of the toggle boxes, the procedure recalculates the number of customers that meet the criteria specified.


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095