Hello! I have been coding for quite a while now, and have become very fond of the Menu command as you can have "Multiple programs" without clogging up the prgm menu. Anyways, I have noticed that exiting a menu can be a bit annoying as I need either a) put a "Quit" Option, which works for most menus, but not if I need to have more than 9 options, and b) press the On button. I was wondering if there was a way to make it so you push a button such as "clear", and it would get rid of the Menu?
Thanks!
Unfortunately, the Menu( command doesn't have this functionality built in; The way to add this functionality is to create a custom menu. There are three routines here on TI|BD in the graphics section for creating custom menus.
- Graph Screen Custom Menu - This is made for the graphscreen on Monochrome calculators. Although quite robust (and arguably, good looking), it involves a fair amount of code and understanding of how TI-Basic works. Setting up the menus and options is as simple as setting the menu options, string length, number of options, and default selection, then going to the predefined label. Simply add an if statement for each submenu-option pair, and the menu can be expanded virtually infinitely. This menu allows you to use the arrow keys + enter or the keypad to select a menu option, pressing [CLEAR] immediately exits the program, and pressing [DEL] will either take you to the main menu, or exit the program if already on the main menu
- Home Screen Multi-Page Menu - This homescreen menu is fairly basic, but effective. You can have up to 9 different pages of menu options, with the only configuration being the strings used and the If statements in the program you are running it from. While this program does not natively have the functionality of using the clear key, it can easily be added with only a few minor tweaks.
- Single Page Menus - These routines are for single page menus only, but are effective if you do not want to use the built in function. As with the Home Screen Multi-Page Menu, it does not have the functionality of using the clear key, but it can easily be added
If you wanted to do that, you can use this as an example:
:Disp "EXAMPLE MENU
:For(I,1,9
:Output(I+1,2,"Option
:Output(I+1,9,I
:End
:1→O
:Repeat max(K={21,105,45
:Output(O+1,1,">
:Repeat Ans
:getKey
:End:Ans→K
:max(1,min(9,O+(K=34)-(K=25
:Output(O+1,1," //One space, this is added here instead of above so the cursor doesn't look like it flickers when it moves
:Ans→O:End
:ClrHome
:Disp "Selected Option:
:O //Shows selected option value and copies it to Ans
Hewwo, my name is Achak Claw. I was formerly BioHazard.
Thanks! This is really useful. I just have a few questions about the code.
- Repeat max(K={21,105,45 - I am pretty sure that this one says "repeat until Key 2nd, enter, clear is pressed but what does the max( mean?
- max(1,min(9,O+(K=34)-(K=25 - I don't know what this one means, my main confusion results from the max( and min( I have tried looking on their respective pages, don't yet know fully what they mean.
If you could help me out with this, that would be great!
Thanks!
You are correct on the first one, in that it is checking for the 2nd, Enter, or Clear key are pressed. However, the calculator processes it like this:
Lets say the key pressed is key 93
// Repeat max(K={21,105,45
First, Evaluate K={21,105,45
{0,0,0}
Take the Max of that list
0
Repeat continues while False
0 = False, according to Boolean logic
So, continue repeating
Now lets say the key pressed is key 105
// Repeat max(K={21,105,45
First, Evaluate K={21,105,45
{0,1,0}
Take the Max of that list
1
Repeat continues while False
1 = True, according to Boolean logic
So, stop repeating and move to the next section of code
You will sometimes also see sum( used instead of max for detecting the key presses. It has the same function, just is a personal preference
The second one is a bit more complicated, but it is setting the upper and lower bounds for the motion. As you probably can guess, max( takes the maximum value of the inputs, and min( takes the minimum value of the inputs. This particular logic also makes use of Piecewise Expressions. So, if we break that piece of code down:
We need starting conditions, so lets assume O is 1 and K is 25;
This means the first option on the menu is selected, and we are trying to move up
//max(1,min(9,O+(K=34)-(K=25
The first thing evaluated is O+(K=34)-(K=25
1 + false - true
1 + 0 - 1
0
The next thing that gets evaluated is the min(9,{result}
min(9,0
0
Finally, the max is max(1,{result}
max(1,0
1
And then it returns; As you can probably see, it is impossible to go above the first option (1)
Now lets assume O is 9 and K is 34;
This means the last option on the menu is selected and we are trying to go down
//max(1,min(9,O+(K=34)-(K=25
The first thing evaluated is O+(K=34)-(K=25
9 + true - false
9 + 1 - 0
10
The next thing that gets evaluated is the min(9,{result}
min(9,10
9
Finally, the max is max(1,{result}
max(1,9
9
And then it returns; From this, it is impossible to go below the last option (9)
Using any other set of starting conditions, the expression will evaluate "normally"
Now lets assume O is 6 and K is 34;
This means we are on the 6th option and trying to go down
//max(1,min(9,O+(K=34)-(K=25
The first thing evaluated is O+(K=34)-(K=25
6 + true - false
6 + 1 - 0
7
The next thing that gets evaluated is the min(9,{result}
min(9,7
7
Finally, the max is max(1,{result}
max(1,7
7
And then it returns; Now the 7th option is selected
Yep, I would agree with Trenly here. There isn't a way to exit the Menu( command unless you put one in. The three methods that Trenly stated are in my opinion the most effective. There is one more that I have used a few times.
It looks like this…
1) Option 1
2) Option 2
3) Option 3
4) Option 4
5) Option 5
6) Option 6
7) Option 7
8) Option 8
You press the corresponding number key to what you would like to do
You would use a repeat loop or a while loop, and you can put in the functionality of using the clear button.