If you wish to return to the top of this page,
click the little blue arrow thingys that look like this
.
Chapter Seventeen: Strings
Chapter Eighteen: Subroutines
Chapter Nineteen: Code Optimization
Chapter Twenty: The Link Port!
Conclusion
Back to tutorial index | Part Four
OK. You know how to work with numbers, variables, graphs, pictures, lists, matrices, and what not. But there's one more variable type we haven't discussed yet: strings. A string is a variable that can store text (a.k.a. words). These are used for storing high score names, entering player names, storing messages to be sent (like in my TI-83 Instant Messengers I and II), and whatever you might need to put words in. Heck, you could even make a word processor!
STRING VARIABLES
The TI-83 and
TI-83+ have 10 string variables. They are named Str1 to Str0. They
hold characters, which can be letters, numbers, punctuation marks,
and tokens (more on them later). The only characters you can't use in
strings are the store symbol (->) and quotation
marks.
There is no limit to the number of characters in a string, but remember that the screen is only 16 characters wide. If your string is over 16 characters long, it will not wrap onto the next line, it will continue off the screen and can be scrolled by using the arrow keys.
PUTTING STUFF INTO STRINGS
OK. So you wanna put some text in a string. First you will need to type your text in quotation marks. So a valid thingy would look like this: "TEXT" .
Then you will
need to type a (guess what) store symbol. Press [STO>].
Then you'll have to dig up the string you want to use from somewhere deep in the menus. Press [VARS]. Then press number 7 or select 7:String... . So now you should be in the VARS \ STRING menu. Then simply choose which Str variable you want to use. Finally, press [ENTER]. Here's an example:

RECALLING STRINGS
Now that you've got Blueberry in Str1, let's say you wanted to display that on the screen from within a program. This is horrendously simple.
:Disp Str1
or
:Output(row,col,Str1)
or whatever else. A string can be treated just like any other old block of text. It can be used like any other variable.
Just don't act stupid and try to perform math on a string. It doesn't work. However, there are a few operations you can use for playing around with strings.
RECEIVING STRING INPUT
Now let's say you want to have the user type in some text. Once again, this is ridiculously simple and quite obvious, but all you do is use Strx in place of any variable for an Input or Prompt command. I do not recommend that Prompt be used with strings. Examples:
Input Str1
Input "ENTER YOUR NAME",Str2
Prompt Str3 (for people who don't believe in user-friendliness)
Now we get to make a program!
It is George W. Bush's Insult Program. Wait and see.
:ClrHome
:Disp "ENTER YOUR NAME"
:Input "",Str1
:ClrHome
:Disp "THAT "+Str1+"," ----- I'll talk about
this line later. For now just enter it in.
:Disp "HE SURE IS"
:Disp "A REAL ASSHOLE"
If you've been paying attention to the 2000 elections you should get this joke.

Ha Ha Ha. Very Funny. Let's hope Dubya never sees this webpage. Let's also hope that Dubya loses the election. Ralph Nader All The Way!
PLAYING WITH STRINGS
No, I don't mean acting like a cat and batting around a piece of string. I'm talking about manipulating and transforming strings. (Oooh... big words there)
The first way of manipulating strings has a very big word. Don't even try to pronounce it. Here it is... concatenation. Essentially that means taking a string and tacking it onto the end of another string, or putting two or more strings together. We have a special command for concatenation: +. Yes, that's a plus sign. So yes, there is one kind of math that can be performed on strings. It is used in an easy way: Just put that plus sign between the strings you want to put together. Examples:
"TI-"+"83"
Str1+"WXYZ"
Str2+Str7
"A"+"B"+"C"+"D"+Str5
etc.
Here's an example:
There's that damn blueberry thing
again.
Now I'll explain that line above. You should understand it now, it displays "THAT " (notice the space), then Str1 immediately afterward, then a comma.
These next commands I will explain cannot be found in any specific menu. They are all found in the Catalog, which is a list of every TI-83 / 83+ command. All commands listed in other menus are also listed here.
To access the catalog, press [2nd] [0] (CATALOG).
To find an item
in the catalog, enter the first letter in that command. Since
Alpha-Lock is on, all you have to do is press the letter, without
having to press [ALPHA] or whatever. Or you
could always scroll with the arrow keys if you're bored. Commands
that don't start with a letter can be reached by either scrolling
upwards from the beginning or pressing theta ( 0, above the 3).
Press [ENTER] to paste that command to the home screen or program editor or wherever you might happen to be.
Here they are:
length(string)
length( is like the
dim( command for lists and
matrices. It returns the number of characters in a string.
NOTE: If you enter something in a string that consists of more than one character, like sin( or Disp or L6, these count for only one character. Also notice that when you go to delete one of these it deletes the whole thing, you can't delete it character by character. These are called tokens.
sub(string,beginning,length)
sub( makes a mini-string
from a string. Essentially it takes a part of a string.
string is the string (it can
be a variable or just a plain string) that you want to get a part of,
beginning is the position of the
first character in the mini-string, and length is how many more
characters to put into the mini-string.
Example:
Note: I altered this
screen shot slightly to make it more readable. Stupid
blueberry.
It doesn't store the mini-string back into itself. You'll have to store it into its own variable.
inString(string,string-to-look-for[,start])
inString( searches
string for the string-to-look-for. If the string-to-look-for is found in the
string, it returns the
character position where it is located. If not, 0 is returned.
start is optional and
specifies the start of the search. It can be used for skipping over
part of the string, and if it is not
specified the search begins at the first character.
If more than one instance of the string-to-look-for is found in
string then it will only
return the first position.
An example:
:inString("I WANT A
BLUEBERRY","BLUEBERRY")->S
:If S/=0:Disp "SHUT UP!"
So this basically says that if the string BLUEBERRY is found anywhere in the first string, tell the user to shut up. Note how I did this. If BLUEBERRY isn't in the string, don't do anything (S will be 0).
expr(string)
What
expr( does is take the string
and convert it into an expression, then executes it. Remember an
expression is some kind of math. An expression is any calculation you
can do on the home screen. Example: 1+(A-3)X2.
Code:
:Input "ENTER EXPRESSION",Str1
:Disp expr(Str1)
Screen
shot:

Of course the answer depends on what A and X are. But you get the
point.
Equ>String(Yx,Strn)
Note
that the greater-than sign is supposed to be a solid arrow.
Equ>String( takes the contents of
the Y= variable you specify and puts it into a string. If you want to
get the Yx variables, they are in
the VARS \ Y-VARS \ Function... menu. You can't just
type the number. Here's an example:
:Equ>String(Y1,Str1)
:Disp Str1+" IS IN Y1.".
Screen
Shot.
![]()
String>Equ(string,Yx)
This
does the exact opposite of Equ>String. It takes a string and
puts it into the Y= variable of your choice. Note that your string
doesn't have to be a variable, it can be a regular string. Try using
this command, then look in the Y= editor -- surprise! It's
there!
TYPING PUNCTUATION
You might be wondering how to type all these cool punctuation marks. Here's how:
|
Punctuation mark |
Keys to press |
|
. |
Just press [.] |
|
, |
Just press [,] |
|
: |
Press [ALPHA] [.] |
|
! |
Press [MATH] [left arrow] [4] (MATH \ PRB \ 4) |
|
? |
Press [ALPHA] [(-)] |
|
' |
Press [2nd] [MATRX] [2] (ANGLE \ 2) |
LOWERCASE LETTERS!!!
Yes, it is possible to type lowercase letters, to an extent. The lowercase letters you can type are a, b, c, d, e, i, n, p, r, s, t, u, v, w, x, y, and z.
The i is that funky i that has something to do with an imaginary number and the x and y have lines over them.
How to type them
|
Letter(s) |
Key(s) to press or menu |
|
a b c d e r |
Found in VARS \ Statistics... \ EQ \ 2, 3, 4, 5, 6, 7 |
|
i |
Press [2nd] [.] |
|
n x y |
Found in VARS \ Statistics... \ XY \ 1, 2, 5 |
|
p s t z |
Found in VARS \ Statistics... \ TEST \ 1, 0, 3, 2 |
|
u v w |
Press [2nd] [7]/[8]/[9] |
That last chapter turned out to be longer than I thought. But this one will be a lot shorter: there isn't much to explain.
WHAT IS A SUBROUTINE?
A subroutine is a program that contains a set of commands frequently used. So if you were making a game and you didn't want to have to type in all the commands for drawing a ship, you could put those commands in a subroutine called DRAWSHIP and call that program whenever you want to draw the ship.
PROS AND CONS OF SUBROUTINES
|
|
|
|
|
Yes, a subroutine is an actual program, it's not like a special type of mini-program, it's a real program that's listed in the PRGM menu and can be executed like any other program.
USING SUBROUTINES, OR CALLING OTHER PROGRAMS FROM A PROGRAM
This is actually quite simple. If you wanted to call the subroutine DRAWSHIP from within your game, you have to make that subroutine first. Then get into the program editor and press [PRGM]. Press the right arrow twice so that EXEC is highlighted. Then select DRAWSHIP from the list. You should see the following in your program editor:
:prgmDRAWSHIP
That signals the calculator to immediately transfer to program DRAWSHIP.
However, if you want to get back to your main program, you must put a Return command at the end of your subroutine (or whenever you want to return to the calling program). This immediately sends you back to the main program, right where you left off. Even if you put Return in a loop it ignores the loop and immediately returns. It is found under PRGM \ I/O \ E.
Some notes:
All variables are global, meaning that all programs that are used by one program can be used by any other program. No such thing as local variables on a TI-83 or 83+. This should be a refreshing change for all you C/C++ programmers out there.
You can't use Goto in one program to jump to a label in another program. Labels are local.
That wasn't that bad now, was it?
Programmers opt for three things: efficiency, program size, and speed.
You always want to make sure that your code is as efficient as can be. Your job as a programmer is to solve the problem (the task the program has to perform) as simply and efficiently as possible. One example is to find alternatives to Goto whenever possible. Subroutines can be a nifty way to organize your program and are very efficient.
Size is another issue. Programs can be huge. So you have to make them as small as possible. Here are some ways to cut down size:
The last parenthesis or quotation mark is optional. Getting rid of it saves space. Output(6,1,"TEXT") can be changed to Output(6,1,"TEXT . Now look at that, you just saved two bytes right there! It might seem like a little, but in a program with lots of text-displaying commands, it can really add up.
Use implied multiplication. If you want to do 3*X, you don't even have to type the *. The calculator will understant 3X and interpret it as 3*X. Those multiplication signs take up space too!
Use the last-answer function, Ans, instead of storing something to a variable. It holds the answer of the last calculation. This not only works on the home screen but in programs as well. Even though you can't see the calculations, they are stored in Ans. It can be found by pressing [2nd] [(-)]. For example:
Instead of using a variable to store getKey keypresses, use Ans. The keypresses are stored in Ans, so they can be recalled. So you can do this:
:getKey
:If Ans=24:Then
do stuff
:If Ans=26:Then
do stuff
etc. You don't even need the extra variable, and it's a hell of a lot faster!!!
Also, a little trick. You know that the Ti-83 has only 27 variables, right? A-Z and theta, right? WRONG!!! Here's a secret. YOU CAN HAVE AS MANY VARIABLES AS YOU WANT!!! All you have to do is use list elements as variables!!! List elements can store numbers, and you can have as many of them as you want! Cool! Lists, especially custom ones, can also be used to store high scores.
See? Now your program will be a lot more efficient. It's always good to practice good programming.
Yes, now we will learn how to use the link port! Unfortunately, the use of the linkport is quite limited. Oh well, let's talk about it anyway!
THE CBL AND CBR
If you don't know what the CBL and CBR are, they're data collection devices. You plug them into your calculator, then you can use all these things, like probes and sensors and stuff like that to collect "real world data". This is more suited for science class than gaming, though, there are already a lot of CBL and CBR programs out there, and most people don't have one. If you're not a teacher or whatever and you've got one then you're a real geek.
The truth is, I really don't know how to use these commands. None of us will probably ever use them, so it shouldn't really matter. If you really want to know, go to one of the other TI web sites.


Anyway, you use the Get( and Send( commands, which are PRGM \ I/O \ A and B. Get( gets data from the CBL or CBR, and Send( sends commands to the CBL or CBR. You have to give the command a list of numbers (in curly brackets separated by commas) that specify various things, like the type of probe and things like that. I don't know what the numbers are. The usage can probably be found on one of the other webpages.
GetCalc(
This is a usage of the linkport more suited for games. But all you can do is get a variable from a calculator, you can't send data, so it somewhat limits the usage of the command.
It's used like this: GetCalc(variable). It is in PRGM \ I/O \ 0.
variable can be a number variable, list, list element, matrix, matrix element, string, Y=, GDB, or Pic. The variable is stored to the variable of the same name on the receiving calculator.
With some creativity you can manipulate this command and make cool link-play games or chat programs. I'm not going to tell you how, but if you've been paying attention all this time you could probably figure it out.
Well, that's it! Twenty chapters, covering practically everything on the TI-83. There's not much more to say, but if you've started from having no programming knowledge and learned all this crap, then congratulations! Happy Programming.