AccessMyLibrary provides FREE access to millions of articles from top publications available through your library.

Magic menus. (The Fox Files) (column)

Data Based Advisor

| July 01, 1990 | Goley, George F. | COPYRIGHT 1989 Advisor Publications, Inc. (Hide copyright information)Copyright

You can add menus that are hot" during a READ, simply by using a bit of ingenuity and the techniques detailed in this article

Last month we covered windows as event triggers. FoxPro lets you give your users the chance to pick any window anytime when using their program. In this article I'll examine menus in the same way, plus we'll design a program control scheme that acts on events triggered by users. While READing a series of GETS, good event-driven programming practice requires us to provide the user with a method of directly selecting a menu option. Unfortunately, FoxPro doesn't include a command like FoxBASE+/Mac's ON MENU command. ON MENU allows users to exit a READ and make a menu selection with a single mouse click. Adding menus that are "hot" during a READ will be an important addition to the next version of FoxPro. But for now, we'll have to use a little ingenuity to get it done. Actually, providing keyboard access to the menu system isn't terribly difficult. We'll do it by assigning the string "MENU" to the memory variable, hotevent, when the user presses a designated hotkey. Then we'll add code to our event handler that recognizes this "special" hot-key event. Next, we'll direct the event handler to read the menu when it encounters this event. Finally, we'll return a message to the calling program that a menu selection has been made. We'll need a menu system to test this technique. The following code should work well enough:

 
* MENU.PRG 
* Menu for event-driven programming demo 
PUBLIC mainmenu(3,2) 
mainmenu="" 
mainmenu(1,1)="Data Entry" 
mainmenu (2, 1) ="Reports" 
mainmenu (3, 1)="Utilities" 
PUBLIC dataentr(3) 
dataentr(1)="Customers" 
dataentr(2)="Inventory" 
dataentr(3)="Sales" 
PUBLIC reports(3) 
reports(1)="Customer List" 
reports(2)="Inventory List" 
reports(3)="Sales Listing" 
PUBLIC utils(2) 
utils(l)="Reindex" 
utils(2)="Quit" 
MENU BAR mainmenu, 3 
MENU 1,dataentr,3,3 
MENU 2,reports,3,3 
MENU 3,utils,2,2 
PUBLIC kbar,kopt 
STORE 0 TO kbar,kopt 
* eof menu.prg 

The easiest way to invoke menus with a keystroke involves using the Esc key. Since Esc exits the READ for us, and since we can cheek for an Esc exit with the READKEY() function, all we have to do is adjust the following case statement in LBREAD.PRG for our Esc "trigger."

 
CASE exitkey--12.OR.exitkey--268    Esc exited the READ 
READ MENU BAR TO kbar,kopt       && RKAD menu 
retval="MENU"      tell calling program 
                   about the manu selection 

If you don't want to use Esc, you need to use the lbhotkey procedure to force the exit from the READ and to alert LBREAD.PRG to the menu selection. This can be done by adding the following line to LBREAD.PRG, the calling program, or the application's set-up program:

ON KEY LABEL F9 DO lbhotkey WITH "MENU" Obviously, you can substitute any key for the F9 key. Another CASE statement for LBREAD.PRG will finish the job:

 
CASE … 
Related articles from newspapers, magazines, journals, and more
Locating menu bar in Outlook Express.
News wire article from: Asia Africa Intelligence Wire January 13, 2005 700+ words
Menu madness, or the mystery of MDI. (Multiple Document...
Magazine article from: Data Based Advisor Spence, Rick May 1, 1995 700+ words
Build a menu system that makes sense to users.(Interface Design)(Tutorial)
Magazine article from: Data Based Advisor Wilchins, Riki Anne July 1, 1995 700+ words
Maximizing the CA-Clipper 5.3 menu system. (Hardcore Clipper)(Column)(Tutorial)
Magazine article from: Data Based Advisor Gutierrez, Dan D. December 1, 1995 700+ words
New Paradox add-in develops menus three levels deep. (Grass Valley...
Magazine article from: Data Based Advisor November 1, 1990 700+ words
©2013 Gale, a part of Cengage Learning. All rights reserved. Contact us | Privacy policy | Terms and conditions

The AccessMyLibrary advertising network includes: womensforum.com GlamFamily