Este código sirve para que el usuario pueda elegir opciones en un menú desplegable con opción a usar teclas de acceso rápido:
'Menualt.bas Ray Thomas February 2002
OPTION BASE 1
DIM MenuItem(7) AS STRING * 25 'Define the menu item array
DIM ChooseItem AS INTEGER 'Currently chosen menu item
DIM XMenuposn AS INTEGER 'Controls the menu item X positions
DIM YMenuPosn AS INTEGER 'Controls the menu item Y positions
DIM Count AS INTEGER 'Array counter
DIM EndMenu AS INTEGER 'F, Enter or Alt keys pressed
DATA F1 - Add a record, F2 - Remove a record, F3 - Modify a record
DATA F4 - Search database, F5 - Print a report, F6 - Display all records
DATA F7 - Quit the program
ChooseItem = 1 'Starting point of highlighted menu item
XMenuposn = 20 'X starting point of menu
YMenuPosn = 6 'Y starting point of menu
'*** Fill the MenuItme Array ***
FOR Count = 1 TO UBOUND(MenuItem$)
READ MenuItem(Count)
NEXT Count
CLS
PRINT
PRINT " Use the Enter key to choose the highlighted menu item or"
PRINT " Press the F number key associated with the menu item or"
PRINT " Press the Alt key and the capitalised letter of the menu item"
GOSUB DrawMenu
'*** get cursor key movements and redraw menu ***
DO
Cmmnd$ = (INKEY$)
IF LEN(Cmmnd$) = 2 THEN Cmmnd$ = RIGHT$(Cmmnd$, 1)
IF Cmmnd$ = "8" OR Cmmnd$ = CHR$(72) THEN GOSUB MoveUp
IF Cmmnd$ = "2" OR Cmmnd$ = CHR$(80) THEN GOSUB MoveDown
IF Cmmnd$ = "7" OR Cmmnd$ = CHR$(71) THEN ChooseItem = 1
IF Cmmnd$ = "1" OR Cmmnd$ = CHR$(79) THEN ChooseItem = UBOUND(MenuItem)
IF Cmmnd$ = CHR$(13) THEN EndMenu = 1
IF Cmmnd$ = CHR$(59) OR Cmmnd$ = CHR$(30) THEN
ChooseItem = 1
EndMenu = 1
END IF
IF Cmmnd$ = CHR$(60) OR Cmmnd$ = CHR$(19) THEN
ChooseItem = 2
EndMenu = 1
END IF
IF Cmmnd$ = CHR$(61) OR Cmmnd$ = CHR$(50) THEN
ChooseItem = 3
EndMenu = 1
END IF
IF Cmmnd$ = CHR$(62) OR Cmmnd$ = CHR$(31) THEN
ChooseItem = 4
EndMenu = 1
END IF
IF Cmmnd$ = CHR$(63) OR Cmmnd$ = CHR$(25) THEN
ChooseItem = 5
EndMenu = 1
END IF
IF Cmmnd$ = CHR$(64) OR Cmmnd$ = CHR$(32) THEN
ChooseItem = 6
EndMenu = 1
END IF
IF Cmmnd$ = CHR$(65) OR Cmmnd$ = CHR$(16) THEN
ChooseItem = 7
EndMenu = 1
END IF
GOSUB DrawMenu
LOOP UNTIL EndMenu = 1
PRINT
COLOR 16, 10
PRINT "Item chosen = "; MenuItem(ChooseItem)
END
DrawMenu:
'Draw the menu
LOCATE YMenuPosn, XMenuposn
FOR Count = 1 TO UBOUND(MenuItem$)
IF Count = ChooseItem THEN COLOR 4, 2 ELSE COLOR 2, 4
LOCATE CSRLIN, XMenuposn
PRINT MenuItem$(Count)
NEXT Count
RETURN
MoveUp:
IF ChooseItem = 1 THEN
ChooseItem = UBOUND(MenuItem$)
ELSE
ChooseItem = ChooseItem - 1
END IF
RETURN
MoveDown:
IF ChooseItem = UBOUND(MenuItem$) THEN
ChooseItem = 1
ELSE
ChooseItem = ChooseItem + 1
END IF
RETURN