TI-Basic 84 Programming/Basic Variables

What are Variables?

TI-Basic is unusual among programming languages in that it does not support actual variables. Instead, all data are treated like files; there is no distinction between an ordinary number and an image, for example. TI refers to all files as "variables;" henceforth "variable" will refer to a file usable by a program. "Variables" are the meat of any programming language - they are used to store and work with data. With variables, the outcomes of programs can differ depending on the user's input or the purpose of the program. Variables in the TI calculators can store different types of data, whether it be numbers, lists of numbers, strings, mathematical functions, etc. However, each data type has its own type of variable that it can be stored in and the rules must be followed fairly strictly.

Storing and Recalling Variables

Variables can be stored and recalled at the Homescreen (the startup screen), or within a program by simply using that variable's name. For example, to recall the variable X at the Homescreen, one would simply type X and hit enter (which would display 10 if X was ten):

X
10

or to recall Str1:

Str1
HELLO WORLD

The format to recall any variable is the same.

To store a value to a variable, you simply state the value you are trying to store, hit the store key (the little arrow), then the variable you are storing to, and then hit enter. For example, making X equal to 52.5 would be as follows:

52.5→X
52.5

It should be noted that 52.5 was displayed after hitting enter on the homescreen. This is because it also recalled the value of the variable after storing it. In programming, the variable isn't actually recalled, but rather the variable is used in some sort of equation. See the individual examples for more help.

Types of Basic Variables

There are many types of variables, but in this chapter, only the most common ones will be dealt with. The Advanced Variables section, will deal with the more complex variable types and uses. The following sections will deal with:

  • Real Numbers (52.5, 100)
  • Lists (1,2,3,4,5)
  • Strings ("APPLES")

Real Numbers

For convenience in this section/chapter, it should be noted that the variables 'A' through 'Z' and the variable theta are considered to be Real Number Variables.

Real number variables store both an integer and decimal part of a number. Examples of real numbers are 0, 2.1, 5, 7.212 or 3.1415926. Reals are accurate up to eight significant digits and can be in the range of -9e99 to 9e99 (that is 9*10^99). If an attempt is tried to exceed this limit the calculator returns an error.

Syntax

To store a number to a Real Variable, the syntax is as follows:

valuevariable
  • Where value is a literal value, a variable, or an expression and
  • Where variable is the variable to store value to
    • Can be 'A' through 'Z' or 'θ'.
      • The variables are accessed by pressing the green ALPHA key, then finding the corresponding green character key on the keypad.


Ex: Literals

5.32→X

Ex: Variable

A→X

Ex: Equation

10/2+36+89/A→X

*Note: In this example, if A was 89, X would be 42, not the actual equation. Only the result of an equation is stored to X (the equation is 5+36+89/89 = 42, so X is 42)


Lists

For convenience in this section/chapter, all lists will be considered as Real Number Lists.

Lists are basically what they sound like - lists of numbers. They are considered by some to be the same as an array. They store a series of numbers that are the same data type (for this section we will assume that it is a Real Number List). The individual numbers of a list are named elements.

Syntax

{value1,value2,...,valueN}→listName
  • Where value1,value2 through valueN are real number elements
    • The number of elements (values) in a list is limited to 999 or the memory of the calculator
    • The minimum number of elements a list can contain is 0
  • Where listName is the name of a list. This can be one of two types:
    • Calculator defined: L1, L2, L3, L4, L5, L6
    • User defined: a small 'L' found via the list menu, followed by up to five characters denoting the name


Ex: Literals

{15,20,30}→L1


Ex: Custom Named list

{1,2,3,4,5}→LLIST1


Ex: List to List

L1→L2

Ex: Equations

{15,20,30}+5→L1

*Note: In this example, L1 would consist of {20,25,35} because each element was increased by five then stored to L1


Strings

Syntax

stringstrN
  • Where string is the string literal, or some other form of string to store to strN and
  • Where strN is one of the predefined strings for the calculator. These are Str1, Str2, Str3, Str4, Str5, Str6, Str7, Str8, Str9 and Str0


Ex: Literals

"MY NAME IS BOB"→Str1

Ex: Str to Str

Str1→Str2

Ex: Combination

"MY NAME IS "+Str1+" AND YOU KNOW IT!"→Str2



Previous: A Basic Program
Next: Output
Table of Contents: TI-Basic 84 Programming