TI-Basic Z80 Programming/Menus

Menus are useful for user interaction. By using Menus, you can list several choices which the user can pick; each choice jumping to a different label.

Menu()Edit

SyntaxEdit

:Menu("Title","Choice1",Label1,"Choice2",Label2,...,"Choice7",Label7)
  • In place of any text string, you may substitute a string variable name (e.g. Str0 or Str1)
  • The title can be up to 16 (display) characters
  • Each choice can be up to 14 characters, any additional characters are truncated
  • Menus can have a limit of 7 options. Attempting to add more options than 7 will result in an "ARGUMENT" error being displayed upon attempted command execution.

ExampleEdit

:Menu("Menu Title","Entry One",A,"Entry Two",B,"Entry Three",C)

If you've entered it in your Calc or VTI, it should display something like:

Menu Title
1:Entry One
2:Entry Two
3:Entry Three

with "Menu Title" highlighted.

It looks best to center the title and fill in the rest with spaces, e.g.

Menu("    Pick One    ","Choice 1",C1,...,"Choice 7",C7)  // 4 spaces on each side

This way, the entire top line will be highlighted.

If you selected 1: and pressed enter, or pressed the 1 key, it should go to label A, if you selected 2: and pressed enter, it should go to label B, and so on.

Menu function is an easy to use function. Just follow the syntax above and you'll be fine! It is equivalent to goto, except the user can choose what to do.

Advanced MenusEdit

The generic menu function allows for great use of static menus, but when more choices are needed or when more interactive, dynamic menus are needed this getKey method tends to work better.

Delvar A                   // Deletes variable A
While not(A                // Begins While loop because nothing is stored to A
getKey→A                 // Stores keypress as A
Text(Y,X,"Menu Header")    // Menu Title
Text(Y,X,"1.First Option") // Displays menu options, repeat for more options
[...]                       // More options
[...]
End                        // End of While loop    
If A=(key press value)     // Defines which part of the code to execute
...                          by what value was stored in A with getKey
...
End                    //Represents end of the If block


For this method to work getKey values are needed in order to correspond with which option the user sees. Alternatively, a simple cursor may be programmed into the menu. This allows for users to press the 2nd key or the enter key to select values:

Delvar K1→C               //Deletes Key variable / Stores the cursor position
Output(0,0,"Title            //Display the menu (this time using output)
Output(C,0,">                //Cursor
Output(1,2,"Menu Item #1     //Menu item
...                          //More possible menu items if necessary
...
Repeat K=21 or K=105     //Display the menu until user presses enter or 2nd
getKey→K                //K is usually the standard for storing the getKey value
If not(K                  //This is a fancy workaround to end the loop prematurely if no key
End                         was pressed. Usually makes the program run faster...
Output(C,0,"              //Clears cursor by outputting a space
(C≠1)(C≠8)((K=34)-(K=25))+C→C         //Find new value for cursor
Output(C,0,">             //Output new cursor position
End
...                       //Code for the rest of your program
...                       



Previous: GetKey
Next: Other Commands
Table of Contents: TI-Basic Z80 Programming

Last modified on 14 March 2013, at 19:42