TI-Basic Z80 Programming/Menus
From Wikibooks, the open-content textbooks collection
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)
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.
0-->A //Setting default value for A While A=0 //Begins While loop for when A=0 getKey-->A //Stores pressed key as A Text(x,y,"Menu Header") //Menu Title Text(x,y,"1.First Option") //Displays menu options, repeat for more options ... //Does the rest of commands in the loop ... End //Defines the end of the 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.
-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!).
-Notes in the template above beginning with // are not part of the code entered in the calculator. Elipsies 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).