Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: p2 on June 15, 2011, 08:49:21 am

Title: Goto a Lbl which is a var
Post by: p2 on June 15, 2011, 08:49:21 am

FIRST QUESTION:
     Is it possible to use the Goto( command, but not as Goto( 1
     I mean if X is 2, it will be Goto( 2 and if X is 7, it will be Goto( 7

SECOND QUESTION:
     Is it possible to combine the Goto( command with a String?
     For Example:    If Str1="AB" it will be Goto( AB and if Str1="B4" it will be Goto( B4

Is One ot them possible?
Title: Re: Goto a Lbl which is a var
Post by: JosJuice on June 15, 2011, 08:50:17 am
No. That is not possible.
Title: Re: Goto a Lbl which is a var
Post by: p2 on June 15, 2011, 08:53:02 am
Is it possible to save a Var (for example X or A) in textmode as an String or to get a Number out of a String and save it in a Var??
Title: Re: Goto a Lbl which is a var
Post by: JosJuice on June 15, 2011, 09:02:21 am
Getting a number out of a string can be done by using expr(. Converting a number to a string can't be done using a TI-BASIC command, but you may be able to create your own routine for doing it (or you could use an asm lib).
Title: Re: Goto a Lbl which is a var
Post by: p2 on June 15, 2011, 09:05:25 am
I don't mean if X=1, "one" will be Srting1
I mean if X=12, "12" will be Str1

Isn't that possible?
Title: Re: Goto a Lbl which is a var
Post by: JosJuice on June 15, 2011, 09:07:05 am
I don't mean if X=1, "one" will be Srting1
I mean if X=12, "12" will be Str1

Isn't that possible?
Converting a string to a number in that way is possible. Converting a number to a string is not possible using a TI-BASIC command.
Title: Re: Goto a Lbl which is a var
Post by: Builderboy on June 15, 2011, 09:33:40 am
It's not possible using a single command, but it is very possible using a few :P

Code: [Select]
:{0,1→L₁
:{0,N→L₂
:LinReg(ax+b) Y₁
:Equ►String(Y₁,Str1
:sub(Str1,1,length(Str1)-3→Str1

Converts number N into String Str1, the number can be any number, integer, decimal, or whatever ^^
Title: Re: Goto a Lbl which is a var
Post by: Deep Toaster on June 15, 2011, 09:46:35 am
TI never made a command in 83P BASIC to convert a number into a string :( Builderboy's code is the best way anybody's found of doing it.
Title: Re: Goto a Lbl which is a var
Post by: aeTIos on June 16, 2011, 10:40:07 am
Yeah, I used that routine too.
Title: Re: Goto a Lbl which is a var
Post by: ralphdspam on June 16, 2011, 12:12:33 pm
Yeah, all of these are not natively supported by pure TI-BASIC, but you can use the following libraries to achieve results.

Is it possible to save a Var (for example X or A) in textmode as an String or to get a Number out of a String and save it in a Var??

You can convert a number to string with this following Celtic III command:
Code: [Select]
det(1,X)→Str1

FIRST QUESTION:
     Is it possible to use the Goto( command, but not as Goto( 1
     I mean if X is 2, it will be Goto( 2 and if X is 7, it will be Goto( 7

SECOND QUESTION:
     Is it possible to combine the Goto( command with a String?
     For Example:    If Str1="AB" it will be Goto( AB and if Str1="B4" it will be Goto( B4

Is One ot them possible?

Using these Celtic III or DCS (I recommend the latter) commands, you can achieve this:

Note that everyone who runs the program MUST have Celtic III or compatible shells (DCS, etc.).

Goto [String]:
Code: [Select]
:Goto 1  \\The reason I have you jump over the first two lines is so that [Free Line] is always 3.
:LBL 0
: \\This is your "Free Line" used as a temporary space to store your temporary code.
:LbL 1
:[Code]
:det(8,"[Prgm Name Without Prgm Token]","Goto " +[String],[Free Line]
:Goto 0
:[More Code]

Example:
Code: [Select]
:Goto 1  \\This is so that Free Line will always be 3.
:LBL 0
:     \\Free Line to be left blank.  
:Lbl 1
:     \\Start of your code :)
:"11"→Str1
:det(8,"TESTPRGM","Goto "+Str1,3     \\This creates the Goto code on line 3 in prgmTESTPRGM.
:Goto 0     \\Jump to the code you just generated.
:
:Lbl 11
:Pause "Blah Blah Blah"

Since you learned how to use Celtic III commands to convert a real variable into a string, you just have to put those two commands together.
Note that this method truncates all the 0's before the number; you will not be able to address Lbl 00,01,02,03,04,05,06,07,08, or 09.

Goto [Real Var]:
Code: [Select]
:Goto 1  \\The reason I have you jump over the first two lines is so that [Free Line] is always 3.
:LBL 0
: \\This is your "Free Line" used as a temporary space to store your temporary code.
:LbL 1
:[Code]
:det(8,"[Prgm Name Without Prgm Token]","Goto " +det(1,[Real Var]),[Free Line]
:Goto 0
:[More Code]

Example:
Code: [Select]
:Goto 1  \\This is so that Free Line will always be 3.
:LBL 0
:     \\Free Line to be left blank.  
:Lbl 1
:     \\Start of your code :)
:randInt(11,13→X     \\Generates a random number from 11-15 and stores it to X.
:det(8,"TESTPRGM","Goto "+det(1,X),3     \\This creates the Goto code on line 3 in prgmTESTPRGM.
:Goto 0     \\Jump to the code you just generated.
:
:Lbl 11
:Disp "You got eleven!"
:Return
:Lbl 12
:Disp "You got 12!"
:Return
:Lbl 13
:Disp "You got XIII!"
:Return
EDIT: Wow, that was longer than expected.  I hope it comes to good use.  :)[/code][/code]
Title: Re: Goto a Lbl which is a var
Post by: Ashbad on June 16, 2011, 12:50:04 pm
What's so bad about if/else/ending statements?  Since it is entirely impossible to put a non-defined constant label address in a goto statement, you have to improvise.  To do something like a switch statement to check to see if an expression in string format refers to a label to be jumped to, you can just check for the sequence with an inString, use the returned index to sub it out, and directly compare it along a set of ifs to see if it matches a sequence that wold do a certain jump.
Title: Re: Goto a Lbl which is a var
Post by: Deep Toaster on June 19, 2011, 11:08:52 pm
And just as a reminder, it's bad practice to use a lot of Lbl/Gotos. Especially in TI-BASIC, which slows down each time you jump out of a conditional like If or For( or While or Repeat.