Similarly, the CHOICE function can return the option selected at a required level in the menu hierarchy. For example:
E> Menu$(1)="Title" Menu$(1,1)="Option 1" Menu$(1,2)="Option 2" Menu$(1,2,1)="Option 2.1" Menu On Do If Choice Then Print Choice(1),Choice(2),Choice(3) Loop
For very large menus, the IF structure as used in the last example would become unwieldy, and cause delays while the menus were being read. AMOS Professional provides a method for handling the largest of menus.
ON MENU PROC
instruction: automatic menu selection
On Menu Proc procedure1
On Menu Proc procedure1,procedure2
Each title in your menu can be assigned its own procedure which will be executed automatically when that option is selected by the user. Like the other ON MENU commands that are described next, ON MENU PROC uses interrupts, which means that it is performed 50 times a second. So your program can be engaged in other tasks while the menus are continually checked by the system.
When automatic selection takes place as the result of ON MENU PROC, the procedure is executed and the program will be returned to the instruction immediately after the ON MENU call. Procedures can make use of the CHOICE function to monitor which option has been triggered, and to perform the appropriate action.
ON MENU GOSUB
instruction: automatic menu selection
On Menu Gosub label1
On Menu Gosub label1,label2
Depending on which option has been selected by the user, ON MENU GOSUB goes to the appropriate subroutine. Unlike Amiga Basic, each title on the menu title bar is handled by its own individual subroutine. After using this instruction, ON MENU should be used to activate the menu system before jumping back to the main program with a RETURN. Also note that the labels used with this command cannot be replaced by expressions, because the label will be evaluated once only when the program is run.