Share via


ON BAR Command

Specifies a menu or menu bar that is activated when you choose a specific menu item from a menu.

ON BAR nMenuItemNumber OF MenuName1   [ACTIVATE POPUP MenuName2
   | ACTIVATE MENU MenuBarName]

Parameters

  • nMenuItemNumber OF MenuName1
    Specifies the menu item number and menu of the menu item that activates another menu or menu bar. Each item in a menu can have another menu or menu bar assigned to it.

    A menu item with a menu or menu bar assigned to it has an arrow placed to the right of the menu item. The arrow indicates that choosing that menu item activates an additional menu or menu bar. An additional space for the cascading submenu arrow is placed to the right of each item if you define the menu with DEFINE POPUP ... MARGIN. If you create the menu without the MARGIN clause, the cascading submenu arrow might overwrite the last character of the menu item.

  • ACTIVATE POPUP MenuName2
    Specifies the name of the menu to activate when the menu item is chosen. Use ON BAR without ACTIVATE POPUP to release a menu from a menu item.

  • ACTIVATE MENU MenuBarName
    Specifies the name of the menu bar to activate when the menu item is chosen. Use ON BAR without ACTIVATE MENU to release a menu bar from a menu item.

Remarks

A menu that displays and activates another menu is called a cascading submenu. Use ON SELECTION BAR or ON SELECTION POPUP to execute a command when an item is chosen from a menu.

The menus and menu bar can be user-defined (created with DEFINE POPUP and DEFINE MENU) or part of the Visual FoxPro menu system.

Example

The following example demonstrates a system of cascading submenus. A menu bar named mnuDinner is created with two menu bar titles. Each title uses ON PAD to activate the menu named popMainCourse or popDessert. The menus named popMainCourse and popDessert each have additional menus named popBurger, popPizza and popPie assigned to their item lists with three ON BAR commands. The popOlives and popPie items have additional menus assigned with two ON BAR commands.

When you make a selection, ON SELECTION POPUP ALL executes a procedure named yourchoice that activates a window and displays your choice. The choice is determined with POPUP( ) and PROMPT( ), which return the name of the menu and the contents (text) of the menu item.

DEFINE WINDOW wOrder FROM 10,0 TO 13,39
DEFINE MENU mnuDinner
DEFINE PAD padOne OF mnuDinner PROMPT '\<Main Course' KEY ALT+M, ''
DEFINE PAD padTwo OF mnuDinner PROMPT '\<Dessert'   KEY ALT+D, ''
ON PAD padOne OF mnuDinner ACTIVATE POPUP popMainCourse
ON PAD padTwo OF mnuDinner ACTIVATE POPUP dessert
DEFINE POPUP popMainCourse MARGIN MESSAGE ;
   'We have burgers and pizza today'
DEFINE BAR 1 OF popMainCourse PROMPT '\<Hamburgers'
DEFINE BAR 2 OF popMainCourse PROMPT '\<Pizza'
ON BAR 1 OF popMainCourse ACTIVATE POPUP burger 
ON BAR 2 OF popMainCourse ACTIVATE POPUP pizza 
DEFINE POPUP burger MARGIN MESSAGE ;
   'What would you like on your burger?'
DEFINE BAR 1 OF burger PROMPT '\<Ketchup'
DEFINE BAR 2 OF burger PROMPT '\<Mustard'
DEFINE BAR 3 OF burger PROMPT '\<Onions'
DEFINE BAR 4 OF burger PROMPT '\<Pickles'
DEFINE POPUP pizza MARGIN MESSAGE ;
   'Here are the available toppings'
DEFINE BAR 1 OF pizza PROMPT '\<Anchovies'
DEFINE BAR 2 OF pizza PROMPT '\<Green Peppers'
DEFINE BAR 3 OF pizza PROMPT '\<Olives'
DEFINE BAR 4 OF pizza PROMPT '\<Pepperoni'
ON BAR 3 OF pizza ACTIVATE POPUP olives 
DEFINE POPUP olives MARGIN
DEFINE BAR 1 OF olives PROMPT '\<Black' MESSAGE 'Black olives?'
DEFINE BAR 2 OF olives PROMPT '\<Green' MESSAGE 'Green olives?'
DEFINE POPUP dessert MARGIN MESSAGE 'Our dessert offerings'
DEFINE BAR 1 OF dessert PROMPT '\<Brownies'
DEFINE BAR 2 OF dessert PROMPT '\<Cookies'
DEFINE BAR 3 OF dessert PROMPT '\<Ice Cream'
DEFINE BAR 4 OF dessert PROMPT '\<Pie'
ON BAR 4 OF dessert ACTIVATE POPUP pie 
DEFINE POPUP pie MARGIN MESSAGE 'What kind of pie?'
DEFINE BAR 1 OF pie PROMPT '\<Blueberry'
DEFINE BAR 2 OF pie PROMPT '\<Cherry'
DEFINE BAR 3 OF pie PROMPT '\<Peach'
DEFINE BAR 4 OF pie PROMPT '\<Rhubarb'
ON SELECTION POPUP ALL DO yourchoice
ACTIVATE MENU mnuDinner
PROCEDURE yourchoice
ACTIVATE WINDOW wOrder 
CLEAR
DO CASE
   CASE POPUP( ) = 'BURGER'
      @ 0,0 SAY 'A ' + POPUP( ) + ' order:'
      @ 1,0 SAY 'You ordered a burger with ' + LOWER(PROMPT( ))
   CASE POPUP( ) = 'PIZZA'
      @ 0,0 SAY 'A ' + POPUP( ) + ' order:'
      @ 1,0 SAY 'You ordered a pizza with ' + LOWER(PROMPT( ))
   CASE POPUP( ) = 'OLIVES'
      @ 0,0 SAY 'A ' + POPUP( ) + ' order:'
      @ 1,0 SAY 'You ordered a pizza with ' ;
         + LOWER(PROMPT( )) + ' olives'
   CASE POPUP( ) = 'DESSERT'
      @ 0,0 SAY 'A ' + POPUP( ) + ' order:'
      @ 1,0 SAY 'You ordered ' + LOWER(PROMPT( )) + ' for dessert'
   CASE POPUP( ) = 'PIE'
      @ 0,0 SAY 'A ' + POPUP( ) + ' order:'
      @ 1,0 SAY 'You ordered ' + LOWER(PROMPT( )) + ' pie'
ENDCASE
WAIT WINDOW
DEACTIVATE WINDOW wOrder
RETURN

See Also

ACTIVATE MENU | DEFINE BAR | DEFINE MENU | DEFINE POPUP | ON SELECTION BAR | ON SELECTION POPUP