Author Topic: Goto a Lbl which is a var  (Read 3561 times)

0 Members and 1 Guest are viewing this topic.

Offline p2

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 849
  • Rating: +51/-11
  • I'm back :)
    • View Profile
Goto a Lbl which is a var
« 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?
*insert supercool signature*

Offline JosJuice

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1344
  • Rating: +66/-14
    • View Profile
Re: Goto a Lbl which is a var
« Reply #1 on: June 15, 2011, 08:50:17 am »
No. That is not possible.

Offline p2

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 849
  • Rating: +51/-11
  • I'm back :)
    • View Profile
Re: Goto a Lbl which is a var
« Reply #2 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??
*insert supercool signature*

Offline JosJuice

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1344
  • Rating: +66/-14
    • View Profile
Re: Goto a Lbl which is a var
« Reply #3 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).

Offline p2

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 849
  • Rating: +51/-11
  • I'm back :)
    • View Profile
Re: Goto a Lbl which is a var
« Reply #4 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?
*insert supercool signature*

Offline JosJuice

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1344
  • Rating: +66/-14
    • View Profile
Re: Goto a Lbl which is a var
« Reply #5 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.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Goto a Lbl which is a var
« Reply #6 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 ^^

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Goto a Lbl which is a var
« Reply #7 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.




Offline aeTIos

  • Nonbinary computing specialist
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3915
  • Rating: +184/-32
    • View Profile
    • wank.party
Re: Goto a Lbl which is a var
« Reply #8 on: June 16, 2011, 10:40:07 am »
Yeah, I used that routine too.
I'm not a nerd but I pretend:

Offline ralphdspam

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 841
  • Rating: +38/-1
  • My name is actually Matt.
    • View Profile
Re: Goto a Lbl which is a var
« Reply #9 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]
« Last Edit: June 16, 2011, 12:21:07 pm by ralphdspam »
ld a, 0
ld a, a

Ashbad

  • Guest
Re: Goto a Lbl which is a var
« Reply #10 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.

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Goto a Lbl which is a var
« Reply #11 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.