Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
KEY Statement (Assignment) Example
◄Example► ◄Contents► ◄Index► ◄Back►
──────────────────────────────────────────────────────────────────────────────
' This example uses the KEY statement to set up one-key equivalents of menu
' selections. For example, pressing F1 is the same as entering the string
' "Add."
' To try this example:
' 1. Choose New Project from the File menu
' 2. Copy the example code below to the code window
' 3. Press F5 to run the example
CLS ' Clear screen
DIM KeyText$(3)
DATA Add, Delete, Quit
FOR I = 1 TO 3 ' Assign soft-key strings from F1 to F3
READ KeyText$(I)
KEY I, KeyText$(I) + CHR$(13)
NEXT I
PRINT " Main Menu": PRINT ' Print menu
PRINT " Add to list (F1)"
PRINT " Delete from list (F2)"
PRINT " Quit (F3)": PRINT
DO
LOCATE 7, 1: PRINT SPACE$(50); ' Get input and respond
LOCATE 7, 1: INPUT " Enter your choice:", R$
SELECT CASE R$
CASE "Add", "Delete"
LOCATE 10, 1: PRINT SPACE$(15);
LOCATE 10, 1: PRINT R$;
CASE "Quit"
EXIT DO
CASE ELSE
LOCATE 15, 1: PRINT "Enter first word exactly as shown"
LOCATE 16, 1: PRINT "or press function key."
END SELECT
LOOP