TI-Basic Z80 Programming/Menus

Menu( ( CTL D) is useful for allowing the user to select an option. By using Menu(, you can list several choices which the user can pick; each choice jumping to a different label.

Syntax
The basic syntax for Menu(:

When a user selects an option in the menu by pressing, the program will jump to the Lbl with the same name defined in the Menu( statement.

If the Menu( statement references a Lbl that does not exist, a <tt>LABEL</tt> error will be returned.

Example
To create a simple menu with several options:

Displays the following when executed:

Advanced Menus
The <tt>Menu(</tt> function allows for great use of static menus, but when more choices are needed or when more interactive, dynamic menus are needed. The following method uses <tt>getKey</tt> to achieve this.

''Note: The following example uses the <tt>Text</tt> command, which draws text to the graph screen. This is covered with more detail in later chapters.''

You try it!
Try these examples to practice using the <tt>Menu(</tt> command.

Physics Calculations
The potential energy of an object is defined by $$PE=mgh$$, where m is the mass in kilograms, g is the gravity, and h is the height in meters. The kinetic energy of an object is defined by $$KE=\frac{1}{2}mv^2$$, where m is the mass in kilograms and v is the velocity in meters per second. The apparent weight of an object is defined by $$W=mg$$, where m is the mass in kilograms and g is the gravity. Use the <tt>Menu(</tt> command to write a simple program that the user can select from each of the previously defined formulas, enter known values, and receive an output.

It is important to use the <tt>Stop</tt> command so that when statements under <tt>Lbl A</tt> and <tt>B</tt> are done executing, the succeeding labels do not execute. However, it is not necessary for a <tt>Stop</tt> command after <tt>Lbl C</tt> statements, since it is the end of the program.