TI-Basic Z80 Programming/Menus

From Wikibooks, open books for an open world
< TI-Basic Z80 Programming
Jump to: navigation, search

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.

Contents

[edit] Menu()

[edit] Syntax

: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.

[edit] Example

: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.

[edit] Advanced Menus

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
...                       


-A "!=" denotes the not equal to operator.

-The Output() command uses the graph screen instead of home screen to display output and can be used in place of Text(). However it uses a different text size and coordinate system for output position (more options on one screen!).

This is false the Output() command uses the Homescreen this CANNOT be used in place of text().

on a second note the Text() command has 2 font sizes.
Ex 1. Text(Y Coord,X Coord,"Text") you do not need the last " and ) i just add it to clarify
Ex 2. Text(-1,Y Coord,X Coord,"Text") (same size as Output() however STILL on graph screen.)


-Notes in the template above beginning with // are not part of the code entered in the calculator. Ellipsis used above are also not involved in actual coding, they are just representative of of possible code. X and Y represent row and column positions where text will be output. The --> is used in place of the store arrow, which assigns values to variables.

Feel free to e-mail if there are questions or if help is needed on other projects (Ryan, pavlovsr@yahoo.com).



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

Personal tools
Namespaces
Variants
Actions
Navigation
Community
Toolbox
Sister projects
Print/export