[comp.databases] dBase III+ menus - a summary

SLORES@umiami.miami.edu (Stanislaw L. Olejniczak) (09/25/89)

Original request:

:In dBase III+ I would like to present a user with a menu, and then have
:the user press one of the FUNCTION keys to choose a menu item.  If
:possible, I would also like very much to display running day's time on
:the display while waiting for a keypress.

Many thanks to all who were so very helpful with this problem.  I
regret I could not reply to all of you individually, but some of the
mail bounced.  

Different respondents had different suggestions; the differences can
be most useful under various conditions.  Below I have included a
summary of some of the answers and hints I received.  At the end of
this message I am including the code I came up with.  I hope you will
find it helpful in your DBase programming.


IN%"roger@tcgould.TN.CORNELL.EDU"  Roger Boissonnas suggested:
>Use the INKEY() function to tell you when the user presses a function key.  It
>will return a negative value when one of the function keys is pressed (I think
>F2 is -1, F3 is -2, and so on, but you can check that with a three line program:
>   do while .t.
>      ? inkey()
>   enddo
>...which will print out the INKEY() value of whatever keys you press).
>No, INKEY()'s function key trapping capabilities are not explained particularly
>well in the manual.
>As for displaying the time, you could just have the INKEY() function within a 
>loop that also displays the system time with the TIME() function.


IN%"mithomas@bsu-cs.bsu.edu"  Michael Niehaus suggested:
>The easiest way to do [it] would be to use dBase III+'s
>"inkey()" function.  The routine would look something like this:
>A=0   &&  A is used to hold key pressed
>DO WHILE A#"Q"
>    @24,0 SAY time()   &&  To continually display time
>    A=INKEY()
>    DO CASE
>        CASE A="A"     &&  Set up a case statement to branch on a
>                       &&  particular command.  If A=0, no key was
>                       &&  pressed, so loop back through again.
>        ...
>    ENDCASE
>ENDDO


IN%"erbo%mango@hub.ucsb.edu"   Eric J. Bowersox suggested:
>For example, if you have a menu where the user needs to press "E", "D", or
>"Q," followed by Enter, and you need to translate that into presses of F2,
>F3, and F4 respectively, you can do the following:
>       SET FUNCTION 2 TO "E;"
>       SET FUNCTION 3 TO "D;"
>       SET FUNCTION 4 TO "Q;"
>
>Alternatively, you can use this syntax:
>
>       SET FUNCTION "F2" TO "E;"
>       SET FUNCTION "F3" TO "D;"
>       SET FUNCTION "F4" TO "Q;"
>
>Then you just need to ask for input via an ACCEPT or @..SAY..GET..READ, test
>a user's response, and branch accordingly.  Be sure to test for bogus input!
>
>...FKMAX(), another function which returns the number of function
>keys available (9 on a PC).
>
>Unfortunately, these days I usually program dBASE IV, where it's _much_
>easier to do both of the above...you can ON KEY specific keys, like the
>F-keys, and put a running clock on the screen with SET CLOCK ON.  Easy to
>do _very_ spiffy looking pulldown menus, too...


IN%"re4%prism@gatech.edu"  Russell Earnest suggested:
>If you are using the INKEY() function to process user input, the example in
>chapter 6, where inkey is discussed, shows how to display the time as you
>desire.
>I also like to add a line to verify input, so my loop looks like this;
>               DO WHILE .T.
>                  i=0
>                  DO WHILE i=0
>                     INKEY()
>                     @ 1,72 SAY TIME()
>                     IF UPPER(CHR(i))$"ACB"
>                        EXIT
>                     ENDIF
>                     i=0
>                  ENDDO
>               DO CASE
>                  CASE (i) $ "Aa"
>                       DO PROCEDURE A
>               ETC. ...........


IN%"mr@cica.indiana.edu"
Michael Regoli sent an interesting implementation of several of the
above ideas.  The code is quite long, so I will not include it here;
however, if Michael does not mind, I will make it available to any who
request it.


IN%"discg1!iesa002@dsac.dla.mil"
John J. Boris,Sr. forwarded a wonderful DBaseIII light bar routine; It
is long, so I will not include it here.  If John does not mind, I will
make it available to indivdual requestors.


The following is my own code;  it does not implement all the
suggestions; a particularily valuable addition would the use of of
FKMAX() suggested by Eric Bowersox  (see above):
============================================================================
*PROGRAM MAINMENU
*
*Presents menu of available choices and launches appropriate procedures
*

M_INITLS = 'XX'
M_DB_NAME = 'DATABASE'

PRIVATE M_CONT

CLEAR
@  3, 25  SAY "FCDS Extractor's Database"
@  6, 25  SAY "Please choose one of the following:"
@  9, 25  SAY "F2    Add records"
@ 11, 25  SAY "F3    Review a record"
@ 13, 25  SAY "F4    Modify a record"
@ 15, 25  SAY "F5    Transfer data to diskette"
@ 18, 25  SAY "F10   QUIT"

M_CONT = .T.

DO WHILE M_CONT
    @ 0, 0  SAY TIME()+ ' on ' + dtoc(DATE())
    i = 0
    i = inkey()
    DO CASE
       CASE i = -1    && F2
            DO ADD_DATA with M_DB_NAME, M_INITLS
            M_CONT = .T.
       CASE i = -2    && F3
            DO REVIEW with M_DB_NAME, M_INITLS
            M_CONT = .T.
       CASE i = -3    && F4
            DO MODIFY with M_DB_NAME, M_INITLS
            M_CONT = .T.
       CASE i = -4    && F4
            DO TO_ASCII with M_DB_NAME, M_INITLS
            M_CONT = .T.
       CASE i = -9    && F10
            M_CONT = .F.
       CASE i = 0     && non-function key
       OTHERWISE    && error messages, other FKEYS 
            @ 0,0 CLEAR TO 0,79
            @ 0,0 SAY 'INCORRECT KEY PRESSED'
            TIMER = 0  && delay to display the error message
            DO WHILE TIMER < 30
             TIMER = TIMER + 1
            ENDDO
            @ 0,0 CLEAR TO 0,79
    ENDCASE
ENDDO       && while M_CONT

RETURN

==============================================================================

My thanks go to:

(in the alphabetical order of addresses)

John J. Boris,Sr        discg1!iesa002@dsac.dla.mil
Eric J. Bowersox        erbo%tangello@hub.ucsb.edu
Greg R. Heflin          heflin@cod.NOSC.MIL         
Michael Niehaus         mithomas@bsu-cs.bsu.edu
Mike Raustad            mraustad@infocenter.UUCP    
Michael Regoli          mr@cica.indiana.edu
Paul Ellis              raelun@ibmpcug.co.uk
Budi Rahardjo           rahardj@ccu.UManitoba.CA  
Russell Earnest         re4%prism@gatech.edu
Roger Boissonnas        roger@tcgould.TN.CORNELL.EDU
David Hiebert           watmath!alberta!david@uunet.uu.net
Bill Wilson             wew@naucse.UUCP             

----
Stan Olejniczak               Internet:         slores@umiami.miami.edu
University of Miami, FL USA   UUCP: (temp void) gould!umbio!solejni
SLORES@UMIAMI.BITNET          UUCP: (?)         umigw!gables!slores
Voice: (305) 547-6571         FAX: (305) 548-4612  
My opinions cannot possibly represent the views of anyone else!