Progress
Programming
Handbook


Example Procedures

The following example defines an integer variable, pay–stat, that can have a value of 1, 2, or 3. It prompts the user to update the variable by displaying it as a radio set. It then redisplays the variable as a fill-in.

By viewing the variable as a radio set, the user is constrained to selecting one and only one of the meaningful values for the variable. Since each integer value represents a different state for an outstanding invoice, the procedure defines meaningful labels that describe these states and displays these in each button, rather than displaying the integer values:

p-radio1.p
DEFINE VARIABLE pay-stat AS INTEGER INITIAL 1 LABEL "Pay Status"
                   VIEW-AS RADIO-SET RADIO-BUTTONS "Unpaid", 1,
                                                   "Partially paid", 2,
                                                   "Paid in full", 3.
FORM
   pay-stat
   WITH FRAME in-frame.FORM
  pay-stat VIEW-AS TEXT
  WITH FRAME out-frame.
     
ON GO OF FRAME in-frame
   DO:
      ASSIGN pay-stat.
      DISPLAY pay-stat WITH FRAME out-frame.
   END. 

DISPLAY pay-stat WITH FRAME in-frame.
ENABLE pay-stat WITH FRAME in-frame.
STATUS INPUT "Select a pay status and GO".

WAIT-FOR WINDOW-CLOSE OF CURRENT-WINDOW. 

NOTE: When you view a field or variable as a radio set, if it is not set to a valid value, it defaults to the first radio button. In the example, pay–stat is explicitly initialized to 1.

When you run this procedure, because pay–stat is initialized to 1, the first radio button is initially chosen. You can either accept that value or choose another button. When you press GO, the value is assigned to pay–stat and then viewed as a text widget.

For example, if you select the second radio button and press GO, the screen appears as follows:

Note that when you select the second button, the first button is automatically deselected.

As with toggle boxes, you can also use the VALUE–CHANGED event with a radio set. This gives the user instant feedback when a new radio button is chosen, as in the following example:

p-radio2.p
DEFINE VARIABLE math-const AS DECIMAL FORMAT "9.999"
        VIEW-AS RADIO-SET RADIO-BUTTONS "e", 2.72,
                                        "pi", 3.14,
                                        "square root of 2", 1.41
        INITIAL 2.72.

FORM
   math-const SKIP
   description AS CHARACTER FORMAT "x(50)"
   WITH FRAME const-frame NO-LABELS TITLE "Common Constants".
                                            
ON VALUE-CHANGED OF math-const
   DO:
      DISPLAY "The value of this constant is approximately " +
              SELF:SCREEN-VALUE @ description WITH FRAME const-frame.
   END. 
   
DISPLAY math-const WITH FRAME const-frame.
ENABLE math-const WITH FRAME const-frame.
APPLY "VALUE-CHANGED" TO math-const.

WAIT-FOR WINDOW-CLOSE OF CURRENT-WINDOW. 

When you run this procedure, the description message changes immediately each time you choose a different radio button.

For example, if you select the second radio button, the screen appears as follows:


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