Input



Input is how we get feedback from the user. We have a nice variety of ways to do this on the TI-89 and the TI-92 as well.

A. The IO screen

As I explained in section II, you can get input on the IO screen using PROMT, INPUT, and INPUTSTR. Now, that you know something about concatenation (&), you can make these somewhat nicer, but I still don't advise using them.

B. The graph screen

Use INPUT with no arguments to allow the user to move the cursor. After pressing enter, the coordinates will be stored in the system variables xc and yc, in function mode, or rc and θc, in polar mode.

C. Dialog and Popups

Dialogs can also be used for input. DROPDOWN string,list of strings, var will bring up a dropdown menu containing all of the elements of the lists. The number of the selected item will be stored in the variable. For example, if you execute:

DemoDD()
Prgm
local A
Dialog
Title "Dropdown Demo"
Dropdown "Choose one",{"HI","Hola","Yo"},A
EndDlog


and select "Yo" from the menu, 3 will be stored into A. Notice that A in this program is local, so it no longer exists once DemoDD is done executing.

REQUEST string,var behaves like INPUTSTR. If you want it to behave like INPUT, simply add EXPR(var) after the dialog.

Ex:

DemoR()
Prgm
Dialog
Title "Request Demo"
Request "Enter a number",A
EndDlog
Expr(A)->A
EndPrgm


If you enter 1, A will be "1", but the EXPR changes it to 1. In other words, A changes from a string to an expression.

The most useful system variable is OK. A dialog box can be exited by pressing enter or esc. If enter is pressed, all variables in REQUEST and DROPDOWN commands are updated and 1 is stored in OK. If esc is pressed, all variables retain their original values, and 0 is stored in OK. Using branching, we can make the program behave differently if the user presses esc.

TIP: If a variable used in a DROPDOWN or REQUEST is already defined within the range of possible values for that command, the input in initially at the value of the variable. For example, in DemoDD above, if we stored 2 in A before the DIALOG, the DROPDOWN would start on "Hola."

IMPORTANT: You cannot use any commands other than TITLE, TEXT, DROPDOWN, or REQUEST between DIALOG and ENDDLOG.

In case you haven't figured it out yet, I love dialog boxes. They are by far the nicest way to share text based information.

Similar to dialog boxes are popups. POPUP list of strings,var behaves like DROPDOWN outside of a DIALOG statement.

D. Toolbars

Believe it or not, that little bar at the top of the screen has some uses other than wasting space. (GASP!) I don't personally like toolbars, but in some cases they are useful. TOOLBAR...ENDTBAR contains a series of Title string[,label]:Item string,label:Item string,label:...:Title string[,label]:Item string,label:... This will replace that bar at the top with the strings following the TITLE statements. When one is chosen and a label follows that TITLE, the program branches to that label. If no label is present, the strings following the ITEM statements drop in a vertical list. When one is selected, the program branches to the appropriate label. Ex:

DemoTB()
prgm
Toolbar
Title "Hello"
Item "Hi?",HI
Item "Yo",YO
Title "Bye"
Item "Adios",A
Item "See ya",SY
EndTBar
lbl HI
...
lbl YO
...
lbl A
...
lbl SY
...
Endprgm


Don'tworry if you don't know what the LBL means. We'll get to that later.

E. Getkey

What if we want to know what key the user just pressed. It's not as hard as you might think (or many people make it). GETKEY() returns the number assigned to the key that was just passed. IMPORTANT: If no key is pressed, GETKEY()=0. Some important keys are the arrows (On the 89, Left=337, Right=340, Up=338, and Down=344) and enter (13 on the 89). If you want a GETKEY number, by this function.

Gkey()
Func
0->a
While a=0
getKey()->A
EndWhile
A
EndFunc


If you don't what WHILE does, you won't understand this. Just know that this waits until a key is pressed (when GETKEY()<>0). then returns the value of the GETKEY(). IMPORTANT: 2nd, Shift, Diamond, and On have no GETKEY(). However2nd, Shift, Alpha, and Diamond affect the GETKEY() of the next button pressed (ex. 2nd Enter is different from Enter).

That's about it. If you understood the last two sections, you'll do fine with conditional statements.


Quiz 2: Input and Output

1. Find the error in this code.

Demo1()
prgm
Dialog
Title "Find the bug"
Dropdown "Look",{"very","very","carefully"},A
If A=3
disp "HI"
Enddlog
Endprgm


Answer: If A=3:Disp "HI" is invalid in DIALOG statement.

2. What will this code do?

Demo2()
prgm
Dialog
Title "Question 2"
Request "Enter",A
EndDlog
Dialog
Title "Guess What?"
Text A&" is the answer"
Enddlog
Endprgm


Answer: Bring up a second dialog box telling you what you entered in the first box.

3. What will this code do?

Demo3()
prgm
Input
PtOn xc,yc
endprgm


Answer: Allow you to move a curosr, then turn on the point you moved the cursor to.

Excellent. Time to move on to something much more interesting: Conditional statements.

<<Previous - Contents - Next>>