Progress
Language Tutorial
for Windows


Combo Box Programming Example

This example creates a simple combo box to represent a variable that lists U.S. time zones. Follow these steps to view the combo box:

  1. Open lt-07-09.p and run it. The display shown below appears:
  2. This application calculates the correct local arrival time of a U.S. domestic flight.

  3. Choose the button for the Departure Time Zone combo box. The drop-down list appears. You select a value as you do with a selection list.
  4. Select a value for the Arrival Time Zone combo box.
  5. Enter a value for Departure Time and Flight Time.
  6. Choose the Calculate button. The application displays the local arrival time.
  7. Choose Exit, then press SPACEBAR to return to the Procedure Editor.

This is the code that created the display:

lt-07-09.p
      /**********  DEFINE WIDGETS  **********/
/*1*/  DEFINE VARIABLE Zone1 AS CHARACTER LABEL "Departure Time Zone" 
        FORMAT "x(10)" INITIAL "Eastern" VIEW-AS COMBO-BOX 
      LIST-ITEMS "Eastern","Central","Mountain","Pacific".
/*2*/  DEFINE VARIABLE Zone2 LIKE Zone1 LABEL "Arrival Time Zone". 
      DEFINE VARIABLE Dtime AS DECIMAL LABEL "Departure Time".
      DEFINE VARIABLE Ftime AS DECIMAL LABEL "Flight Time".
      DEFINE VARIABLE Atime AS DECIMAL LABEL "Arrival Time".
      DEFINE BUTTON btn-Calc LABEL "Calculate".
      DEFINE BUTTON btn-Exit LABEL "Exit".
      /**********  DEFINE FRAMES  **********/
      DEFINE FRAME Frame1
      SKIP(2) Zone1 COLON 22 SPACE(2) Zone2 SKIP(3)
      Dtime COLON 22 SKIP(1) Ftime COLON 22 SKIP(1) Atime COLON 22 SKIP(1)
      btn-Calc TO 22 btn-Exit SKIP(1)
        WITH SIDE-LABELS CENTERED THREE-D
          TITLE "Calculating Local Arrival Times for 
             U.S. Domestic Flights".
      /**********  DEFINE TRIGGERS  **********/
      ON CHOOSE OF btn-Calc
       DO:
/*3*/      Atime = (DECIMAL(Dtime:SCREEN-VALUE) + 
                   DECIMAL(Ftime:SCREEN-VALUE) + 
                  (Zone1:LOOKUP(Zone1:SCREEN-VALUE) -
                  Zone2:LOOKUP(Zone2:SCREEN-VALUE))) MOD 24.
           DISPLAY Atime WITH FRAME Frame1.
       END.
      /**********  MAIN LOGIC  **********/
      DISPLAY Zone1 Zone2 WITH FRAME Frame1.
      ENABLE ALL WITH FRAME Frame1.
      WAIT-FOR CHOOSE OF btn-Exit. 

These notes help to explain the code:

  1. This DEFINE VARIABLE statement sets up the first combo box with the VIEW-AS phrase.
  2. This DEFINE VARIABLE statement uses the LIKE option to inherit the characteristics of the first combo box. The other options override specific inherited characteristics.
  3. This expression uses departure time and flight time to calculate arrival time. It also uses the LOOKUP method of the combo box to determine the index values of the selected time zones. The expression uses these values to adjust the arrival time to the arrival time zone. Finally, the MOD operator keeps the result in 24 hour format.
NOTE: Keep in mind that tooltip information can be added to a combo box widget. Refer to the code examples in either the Toggle Box Programming Example or the Radio Set Programming Example earlier in this chapter that show how to define the TOOLTIP option.


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