< TI-Basic 89 Programming

Input

Input, I/O(F3):3 is a command which will display a string and wait for the user to input a value. The value will then be stored into the specified variable once ENTER is pressed. The behavior of this command changes depending on how many parameters are passed into it, explained below.

Syntax: Input

:Input [''string''],[''var'']
  • Where string is the optional string to display, and var is the optional variable to store the value to
  • If string is provided, the I/O screen will display that string on a new line, then wait for user input.
  • If string is not provided, the I/O screen will display a ? on a new line, then wait for user input.
  • If neither string nor var is provided, it will display the graph screen and wait for the user to select a coordinate (x value of coordinate is stored into xc, and the y value into yc)
  • Providing only string but not var results in an error ("Argument must be a variable name", errornum 140)

Ex: With String

:Input "X Value",x
X Value
5

*The value of 5 would be stored into x

Ex. Without String

:Input x
?
5

*The value of 5 would be stored into x

Ex: Without Arguments

:Input
Pressing ENTER here would store the coordinates into xc and yc, respectively.


InputStr

InputStr, I/O(F3):4 is much like input, but the values inputted into this command will always be a string (so no quotation marks are needed).

Syntax: InputStr

:InputStr [''string''],''var''
  • Where string is an optional string to display instead of ?
  • Where var is the variable the string inputted will be stored into

Ex: InputStr

:InputStr "What is your name",name
What is your name
George

*Pressing ENTER would store "George" into the variable name.

Prompt

Prompt, I/O(F3):5 prompts the user to input a number of variables. While this can be used to input more than one variable with one command, it does not give you the flexibility to change what is displayed on screen.

Syntax: Prompt

:Prompt ''var''[,''var2''][,''var3''][,…''varN'']
  • Where var2 through varN are all optional arguments. Arguments must be valid variable names.
    • Amount of arguments limited only by available memory
  • For each argument, Prompt will wait until a value is entered and ENTER pressed before asking for the next one.

Example: Prompt

:Prompt x,y
x?
5
y?
7

*This would store 5 into x and 7 into y

Request

Request, I/O(F3):1:2 puts a pop-up box on the current screen and allows the user to input a string into it, and then stores that string into a variable. Request can be used as a stand-alone command or as part of a Dialog block (more on those later).

Syntax: Request

:Request ''string'',''var''
  • Where string is the string to be displayed before the input box
  • Where var is the variable the string gets stored into
  • Request automatically turns a-lock on, so the alpha button must be pressed once before numbers and other symbols may be entered

Ex: Request

:Request "name",x
The string put into the input box will be stored into the variable x.


PopUp, I/O(F3):1:3 displays a pop up window with a number of choices for the user to choose between (passed in as a list). Then, the number of the choice the user selects will be stored into the variable given.

Syntax: PopUp

:PopUp ''itemlist'',''var''
  • Where itemlist is a list of strings that will appear in the popup.
  • Where var is the variable that the number of the choice will be stored to.

Example: Correct Equation

:PopUp {"1+2=2","1/2=2","1-2=2","1*2=2"},x
When ENTER is pressed, the value 4 will be stored into x.


Passing in Arguments

Passing in arguments is vital to functions, and can be helpful in programs as well. In order to get an argument to be passed in, it must be declared in the opening parenthesis of the program editor. Then, when calling the program (by typing prgmname() in the home screen), you put the declared arguments into the parenthesis, like so: prgmname(arg). Note: for all of the following examples, the name of the function is "temp" (and it is a function).

Syntax

temp([''var1''][,''var2''][,''var3''][,…''varN''])
  • Where var1 through varN are all valid variable names
    • The amount of variables passed into the function is limited only by the amount of available memory
  • The variables passed in are local variables, as in they disappear the moment program execution stops (unlike from the previous ways of input, where the variables stick around until they are deleted).

Example: Temp

temp(x,y,z)
:Func
:Return x^2+(y*z)/100
:EndFunc

Let's say you call this program like so: temp(12,4,52). The following will appear on your home screen:

▪temp(12,4,52)      146.08

This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.