Progress
Language Tutorial
for Windows


Menu Bar Example

You’ve learned all the basics, so now you can put it all together. This example implements enough of a menu bar to demonstrate what you’ve learned. Perform these steps:

  1. Open lt-11-01.p and run it. The following display appears:
  2. Choose Tables from the menu bar and browse through the submenu and the nested submenu.
  3. Choose the Reports and Help submenus and browse through them.
  4. Choose Reports Mailing Labels. The editor in the window displays the list of customer mailing labels.
  5. Choose Tables Exit.
  6. Press SPACEBAR to return to the Procedure Editor.

First, look at the code that sets up the menu structure:

lt-11-mn.i
      /**********  DEFINE WIDGETS  **********/
/*1*/  DEFINE SUB-MENU sm-Open
          MENU-ITEM mi-Cust        LABEL "&Customer"
          MENU-ITEM mi-Order       LABEL "&Order".

      DEFINE SUB-MENU sm-Table
/*2*/      SUB-MENU sm-Open         LABEL "O&pen"
/*3*/      MENU-ITEM mi-Exit        LABEL "E&xit".

      DEFINE SUB-MENU sm-Reports
          MENU-ITEM mi-Cust      LABEL "&Monthly Summary"
          MENU-ITEM mi-Labels    LABEL "Mailing Labels"
/*4*/      RULE
/*5*/      MENU-ITEM mi-Balances    LABEL "Order Tot&als" DISABLED
           MENU-ITEM mi-Today       LABEL "Order &Items"  DISABLED
           RULE
/*6*/      MENU-ITEM mi-Print       LABEL "&Output to Printer" TOGGLE-BOX.

      DEFINE SUB-MENU sm-Help
          MENU-ITEM mi-Help        LABEL "H&elp".
/*7*/  DEFINE MENU mbar MENUBAR
          SUB-MENU  sm-Table       LABEL "&Tables"
          SUB-MENU  sm-Reports     LABEL "&Reports"
          SUB-MENU  sm-Help        LABEL "&Help".

/*8*/  ASSIGN DEFAULT-WINDOW:MENUBAR = MENU mbar:HANDLE. 

These notes help to explain the include file code:

  1. The DEFINE SUB-MENU statement defines one pull-down menu and the menu items of that pull-down menu. The ampersand (&) in the label, establishes the mnemonic for the menu item (covered later).
  2. This submenu appears as a menu item in the next DEFINE SUB-MENU statement, so its definition must come first.
  3. The Exit menu item is always the last menu item of the first submenu on the menu bar.
  4. Use RULE to provide a graphic divider between groups of menu items. Use SKIP to add space between menu items.
  5. The DISABLED option disables this menu item on startup (covered later).
  6. The TOGGLE-BOX option makes the menu item a toggle (covered later).
  7. The DEFINE MENU statement defines a Progress menu. The MENUBAR phrase makes the menu a menu bar and associates submenus with it.
  8. This critical step makes the window the owner of the menu bar. In this case, the owner is the default window.

Next, look at the following code, which uses the previous menu structure to implement the mailing list report you saw in the last section:

lt-11-01.p
      /**********  DEFINE WIDGETS  **********/
/*1*/  {lt-11-mn.i} /* Menu definition */  
      DEFINE VARIABLE Rep-Editor AS CHARACTER VIEW-AS EDITOR 
          SCROLLBAR-VERTICAL SIZE 76 BY 13.
      DEFINE VARIABLE Stat AS LOGICAL.

      /**********  DEFINE FRAMES  **********/
      DEFINE FRAME Frame1
          Rep-Editor WITH NO-LABELS ROW 2 CENTERED TITLE "Report Output"
        
      /**********  DEFINE TRIGGERS  **********/
/*2*/  ON CHOOSE OF MENU-ITEM mi-Exit 
          APPLY "CLOSE-WINDOW" TO DEFAULT-WINDOW.  

/*3*/  ON CHOOSE OF MENU-ITEM mi-Labels
          RUN p-Report.
    
      /**********  MAIN LOGIC  **********/
      ASSIGN Rep-Editor:READ-ONLY IN FRAME Frame1 = YES
             Rep-Editor:FONT = 3.
      ENABLE ALL WITH FRAME Frame1.
/*4*/  WAIT-FOR CHOOSE OF MENU-ITEM mi-Exit.

      /**********  INTERNAL PROCEDURES  **********/
/*5*/  PROCEDURE p-Report:
      OUTPUT TO "tut-temp.txt".
      FOR EACH Customer FIELDS (Balance Postal-Code Contact Name Address
          Address2 City St) WHERE Balance >= 1400 BY Postal-Code:
           PUT Contact SKIP
              Name SKIP
              Address SKIP.     
          IF Address2 NE "" THEN PUT Address2 SKIP.    
          PUT City + "," + St + " " + STRING(Postal-Code, "99999")
              FORMAT "x(23)" SKIP(1).
          IF Address2 EQ "" THEN PUT SKIP(1).
       END. 
      OUTPUT CLOSE.
        
     ASSIGN Stat = Rep-Editor:READ-FILE("tut-temp.txt") IN FRAME Frame1.
      END PROCEDURE. 

These notes help explain the main code:

  1. This reference includes the menu structure in the procedure.
  2. Choosing the Exit menu item ends the application by closing the window.
  3. Like most menu items, choosing this item executes a RUN statement to an internal or external procedure. Here, the internal procedure runs a report.
  4. The Exit command of the menu bar satisfies the WAIT-FOR condition by closing the application window.
  5. The internal procedure executes the customer mailing label report.

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