83Plus:Basic:Tricks

From WikiTI
Revision as of 12:21, 27 May 2006 by Saibot84 (Talk | contribs)

Jump to: navigation, search


Please format this article according to the guidelines and Wikification suggestions, then remove this {{Wikify}} notice from the article.


Ans your answers
the Ans var is, IMHO, the most useful yet most unsafe var on the whole calculator because it can be so many different variable types (real, complex, list, matrix, string)... One way to reduce the number of varables you're using in your program is to carefully structure your program so that it stores as much information into the Ans var as possible. One way to do this is to setup Ans to be a list, say {3,1,4,2,5}. Doing Ans(4) is not going to multiply each value in the list by four, but rather going to give you the 4th value in the list:2. This happens because the OS will treat the Ans variable exactly the same as if it were L1 or any other list variable. I've already demonstrated that the Ans var can be used to keep track of whether one of the keys we were looking for was found or not, but there are other things you can do with the Ans var (as long as you're careful not to change the value in Ans unintentionally). For instance, doing {Ans(2),Ans(4),Ans(1),Ans(3),Ans(5) will change Ans to be the list {1,2,3,4,5}... Note that the Ans var is changed AFTER the whole command has been executed. There will probably be more examples of using Ans in a program at a later date. Therefore, you can do something like this:
(50% tested)
(to convert from Pt coordinates to Pxl coordinates)
A is the X-coord
B is the Y-coord

{63/(Ymax-Ymin),95/(Xmax-Xmin

;{pixels per Y, pixels per X

{abs(Ymax-B),abs(Xmin+A),int(Ans(2))+(0=fPart(Ans(2))),int(Ans(1))+(0=fPart(Ans(1

;{Y,X,int ppY,int ppX
;Ans(1)Ans(3) is now the Pxl-Y
;Ans(2)Ans(4) is now the Pxl-X
Autodetect Degree or Radian Mode
Robert Maresh states that this is one thing he learned from James Matthew's Asmguru.hlp
:If 0<cos(9)
:Then
:Disp "Degree Mode
:Else
:Disp "Radian Mode
:End
Autodetect if the Calculator is an 82 or 83/+
Robert Maresh states that
abs -1+1 would return 2 on a TI-82
abs(-1+1 would return 0 on a TI-83 (this is because the abs is followed by a parenthese)

and that one can therefore use the following to display whether the calc is an 82 or 83

Text(0,0,"YOU HAVE A TI-",83-.5(abs -1+1

Miscellaneous

Have conditions built into your formulas
This will probably need a better explanation, but I have found it useful to build certain conditions into my formulas, instead of having to write all those If statements... for instance, for piece-wise graphing, you can do Y=(X^2)(X>0)+(2X)(X<1), which is the same as If X>0:Y=X^2:If X<1:Y=2X ...right now, I can't really say what you'll be saving by doing this (memory/speed/etc) because I don't remember, but I can assure you this come quite in handy because you can then have one formula solve a variety of different problems, without the hassle of dealing with a lot of If-Then statements. For example, if you were to save that formula as Y1, then you'd only need to do Y1(number) to have it do the whole sequence of conditionals. I consider this one of the more complicated tricks to implement (because one can easily get confused as to how to build it as well as to what conditions one is looking for) but I have found it to be extremely useful. For example, let us say you write a text editor program in BASIC that allows the user to edit Str1, as displayed on the homescreen using Output(1,1,Str1. However, you run into a problem when Str1 is longer than the 96 chars that fit on the homescreen, so you can, using the sub( and length( functions, you could have one line of code something like
:length(Str1
:Output(1,1,sub(Str1,1(Ans<96)+16frac(Ans/16)(Ans>95)+(16int(Ans/16)-80)(Ans>95),Ans+80-16int(Ans/16
should make the Output scroll up one line whenever the screen has been filled (untested, please verify). What this line is saying is: give me from Str1, starting at the first byte if Str1 is smaller than 96 charachters, otherwise, calculate the beginning to be one "row" less than the total, and give me all the rest of the chars till the end. If you could not follow that, don't worry, as that is what I meant when I said this is one of the harder tricks. If you did follow with what I was trying to do, Kudos to you! Keep in mind that the conditions within the () can hold any of the condition-elements of If statements, i.e. and, not, or, =, ≠, >, <, ≥, ≤. BTW, this BASIC trick does NOT work on the 89. I tried, but there I could not get the 89 to convert a binary operation into a numerical value, the way the z80s do. (I could be wrong about this working on all z80s... I've tested it on an 82 and an 83+)
See program in MirageOS

If you want to see your program in a shell, like MirageOS, you must type the following code in the first line of the program:

::"Description

That will show the program name with the description you typed.

Special Thanks

Special thanks to:

Kevtiva Inc. http://web.archive.org/web/20021010114152/www.kevtiva.com/calc/index.html © 2000 Kevtiva Interactive

BASIC Guru Online http://bgo.netfirms.com/ Copyright © 2000-2006 BASIC Guru Online. All Rights Reserved.