Author Topic: Help with sub(  (Read 2601 times)

0 Members and 1 Guest are viewing this topic.

Offline Scipi

  • Omni Kitten Meow~ =^ω^=
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1547
  • Rating: +192/-3
  • Meow :3
    • View Profile
    • ScipiSoftware
Help with sub(
« on: December 02, 2010, 08:27:07 pm »
I'm writing a small program in TI-BASIC to calculate derivatives, The way I have it so far is that when the final element inputed is to the 1st power, the result is written as x^0. Example: 5x^4+3x^1 would result in 20x^3+3x^0.

I'm trying to cut out that last bit but I keep getting an invalid dim error.

Here's the code I wrote to parse put that bit.
Code: [Select]
:sub(Str2,length(Str2)-2,length(Str2)->X
:if x="^0"
:sub(Str2,1,length(Str2)-2)->Str2

Imma Cat! =^_^= :3 (It's an emoticon now!)
Spoiler For Things I find interesting:
Spoiler For AI Programming:
Spoiler For Shameless advertising:

Spoiler For OldSig:





Spoiler For IMPORTANT NEWS!:
Late last night, Quebec was invaded by a group calling themselves, "Omnimaga". Not much is known about these mysterious people except that they all carried calculators of some kind and they all seemed to converge on one house in particular. Experts estimate that the combined power of their fabled calculators is greater than all the worlds super computers put together. The group seems to be holding out in the home of a certain DJ_O, who the Omnimagians claim to be their founder. Such power has put the world at a standstill with everyone waiting to see what the Omnimagians will do...

Wait... This just in, the Omnimagians have sent the UN a list of demands that must be met or else the world will be "submitted to the wrath of Netham45's Lobster Army". Such demands include >9001 crates of peanuts, sacrificial blue lobsters, and a wide assortment of cherry flavored items. With such computing power stored in the hands of such people, we can only hope these demands are met.

In the wake of these events, we can only ask, Why? Why do these people make these demands, what caused them to gather, and what are their future plans...

Offline Yeong

  • Not a bridge
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3739
  • Rating: +278/-12
  • Survivor of Apocalypse
    • View Profile
Re: Help with sub(
« Reply #1 on: December 02, 2010, 08:33:46 pm »
isn't last index is supposed to be 1 lower?
:sub(Str2,length(Str2)-2,length(Str2)-1->X
like this
I believe string value starts with 0.
Sig wipe!

Offline FinaleTI

  • Believe in the pony that believes in you!
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1830
  • Rating: +121/-2
  • Believe in the pony that believes in you!
    • View Profile
    • dmuckerman.tumblr.com
Re: Help with sub(
« Reply #2 on: December 02, 2010, 08:34:33 pm »
I'm writing a small program in TI-BASIC to calculate derivatives, The way I have it so far is that when the final element inputed is to the 1st power, the result is written as x^0. Example: 5x^4+3x^1 would result in 20x^3+3x^0.

I'm trying to cut out that last bit but I keep getting an invalid dim error.

Here's the code I wrote to parse put that bit.
Code: [Select]
:sub(Str2,length(Str2)-2,length(Str2)->X
:if x="^0"
:sub(Str2,1,length(Str2)-2)->Str2

For one, you can't store a string to X or any real var, and two, that first sub string tries to copy a sub string from two spaces before the end of the string that is the length of the whole string.
sub() works like: sub(String,start position,length of sub string), not sub(String,start position,end position).

Try this code and see if it works:
Code: [Select]
sub(Str2,length(Str2)-1,2
If Ans="^0
sub(Str2,1,length(Str2)-2 -> Str2

Edit: To clarify this:
isn't last index is supposed to be 1 lower?
:sub(Str2,length(Str2)-2,length(Str2)-1->X
like this
I believe string value starts with 0.
It actually starts at 1.
« Last Edit: December 02, 2010, 08:36:23 pm by FinaleTI »


Spoiler For Projects:

My projects haven't been worked on in a while, so they're all on hiatus for the time being. I do hope to eventually return to them in some form or another...

Spoiler For Pokemon TI:
Axe port of Pokemon Red/Blue to the 83+/84+ family. On hold.

Spoiler For Nostalgia:
My big personal project, an original RPG about dimensional travel and a few heroes tasked with saving the world.
Coding-wise, on hold, but I am re-working the story.

Spoiler For Finale's Super Insane Tunnel Pack of Doom:
I will be combining Blur and Collision Course into a single gamepack. On hold.

Spoiler For Nostalgia Origins: Sky's Story:
Prequel to Nostalgia. On hold, especially while the story is re-worked.

Offline yunhua98

  • You won't this read sentence right.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2718
  • Rating: +214/-12
  • Go take a dive in the River Lethe.
    • View Profile
Re: Help with sub(
« Reply #3 on: December 02, 2010, 08:36:36 pm »
first of all, you can't store a substring into a variable like "X", and second, when you have length(Str2)-2,length(Str2), that means however many tokens in Str2 minus two is the token you start from, but you want to go the length of Str2!  so you get Invalid Dim.

tl:dr:  syntax of Sub is "sub([string],[token # to start from],[# of tokens])"

EDIT:  super ninja'd  :P
« Last Edit: December 02, 2010, 08:37:00 pm by yunhua98 »

Spoiler For =====My Projects=====:
Minor setback due to code messing up.  On hold for Contest.
<hr>
On hold for Contest.


Spoiler For ===Staff Memberships===:






Have you seen any good news-worthy programs/events?  If so, PM me with an article to be included in the next issue of CGPN!
The Game is only a demo, the code that allows one to win hasn't been done.
To paraphrase Oedipus, Hamlet, Lear, and all those guys, "I wish I had known this some time ago."
Signature Last Updated: 12/26/11
<hr>

Offline Yeong

  • Not a bridge
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3739
  • Rating: +278/-12
  • Survivor of Apocalypse
    • View Profile
Re: Help with sub(
« Reply #4 on: December 02, 2010, 08:37:02 pm »
Oops. Ignore mine. I think I was confused with java.
Sig wipe!

Offline Scipi

  • Omni Kitten Meow~ =^ω^=
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1547
  • Rating: +192/-3
  • Meow :3
    • View Profile
    • ScipiSoftware
Re: Help with sub(
« Reply #5 on: December 02, 2010, 08:47:59 pm »
Quote
EDIT:  super ninja'd

Try Uber ninja'd  :D I just got ninja'd three times over!

Thank you everyone. I just started working with the sub( function yesterday so I'm not too familiar with them.

Imma Cat! =^_^= :3 (It's an emoticon now!)
Spoiler For Things I find interesting:
Spoiler For AI Programming:
Spoiler For Shameless advertising:

Spoiler For OldSig:





Spoiler For IMPORTANT NEWS!:
Late last night, Quebec was invaded by a group calling themselves, "Omnimaga". Not much is known about these mysterious people except that they all carried calculators of some kind and they all seemed to converge on one house in particular. Experts estimate that the combined power of their fabled calculators is greater than all the worlds super computers put together. The group seems to be holding out in the home of a certain DJ_O, who the Omnimagians claim to be their founder. Such power has put the world at a standstill with everyone waiting to see what the Omnimagians will do...

Wait... This just in, the Omnimagians have sent the UN a list of demands that must be met or else the world will be "submitted to the wrath of Netham45's Lobster Army". Such demands include >9001 crates of peanuts, sacrificial blue lobsters, and a wide assortment of cherry flavored items. With such computing power stored in the hands of such people, we can only hope these demands are met.

In the wake of these events, we can only ask, Why? Why do these people make these demands, what caused them to gather, and what are their future plans...

Offline jnesselr

  • King Graphmastur
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2270
  • Rating: +81/-20
  • TAO == epic
    • View Profile
Re: Help with sub(
« Reply #6 on: December 02, 2010, 08:54:39 pm »
Quote
EDIT:  super ninja'd

Try Uber ninja'd  :D I just got ninja'd three times over!

Thank you everyone. I just started working with the sub( function yesterday so I'm not too familiar with them.
It's all good. Personally, I wish it could return null strings, and had that last item be the end index instead of length, but whatever.  I think it works well when used correctly.