For something like that, you could do a large number of things: Remove with constants and tell people to always add the ), fix the 2nd number remover to stop at a parenthesis, pull the #X+# part out of the parenthesis, etc. Your choice
» Forum
> Your Projects

As per your post which you deleted and haven't put back on here
Quote:
:sub(Str1,1,inString(Str1,"X")1→Str2
:inString(Str1,"+")
:sub(Str1,Ans+1,length(Str1)Ans→Str3
:expr(Str2→A
:expr(Str3→B
Str1 = "(3X+2)"
I keep getting a syntax error. Why?
The reason is because Expr() is trying to execute this line (which, if you try it at the homescreen, it will fail too) "2)". You will have to get rid of the ending parenthesis however you choose to do so. :inString(Str1,"+")
:sub(Str1,Ans+1,length(Str1)Ans→Str3
:expr(Str2→A
:expr(Str3→B
Str1 = "(3X+2)"
I keep getting a syntax error. Why?
Str1 = "(3X+2)"
sub(Str1,inString(Str1,"+")+1,inString(Str1,")")1→Str3
The above line returns a dim error. For why????
sub(Str1,inString(Str1,"+")+1,inString(Str1,")")1→Str3
The above line returns a dim error. For why????
Because inString() returns the position in the string that it finds the value. For instance, inString("ABCDEF","D") will return 4 because that is how far into the string it is. Sub(,,LENGTH) does not work exactly right with inString(), so you have to find some way to transfer the position to a length from your current position.
Well, this line seems to work
sub(Str1,inString(Str1,"(")+1,inString(Str1,"X")1→Str2
but, this one doesn't
sub(Str1,inString(Str1,"+")+1,inString(Str1,")")1→Str3
sub(Str1,inString(Str1,"(")+1,inString(Str1,"X")1→Str2
but, this one doesn't
sub(Str1,inString(Str1,"+")+1,inString(Str1,")")1→Str3
The difference with those two is: in the first one, the 1 is your current position in the string (give or take). For the second one, you could supply your current position (minus one?) and subtract it instead of 1. So, you could put inString(Str1,"+")+1 on the line before, and use Ans as the second argument of Sub() and your instring(,")") minus Ans to get the correct link (Subject, of course, to offby1, I bet)
sub(Str1,inString(Str1,"(")+1,inString(Str1,"X")1→Str2
It doesn't give any errors, but it returns "0", not "3"
It doesn't give any errors, but it returns "0", not "3"
Check what the value of Str2 is. I have a feeling it might be "(" which, when expr()'d, would return 0 (I think). Other than that, it looks like it is correct.
Str2 is "3X". Let me fix that
Edit: sub(Str1,inString(Str1,"(")+1,inString(Str1,"X")2→Str2
I changed it to "2". It now stores Str2 as "3", expr( gives A a value of "3"
Edit: sub(Str1,inString(Str1,"(")+1,inString(Str1,"X")2→Str2
I changed it to "2". It now stores Str2 as "3", expr( gives A a value of "3"
Ah, very nice Just as a small note of why that worked, if you changed the code to this:
Code:
It would still work, because that value of 2 is the same as inString(Str1,"(")+1, which is the same as your current position, the start of the number, in the string.
Code:
inString(Str1,"(")+1
sub(Str1,Ans,inString(Str1,"X")Ans>Str2
I'm going to try this:
:sub(Str1,inString(Str1,"+")+1,((inString(Str1,")"))(inString(Str1,"+")+1))→Str3
:sub(Str1,inString(Str1,"+")+1,((inString(Str1,")"))(inString(Str1,"+")+1))→Str3
Ok. I have this line of code which returns a syntax error. I've been looking at these so much, I can't even tell anymore >.<
Code:
Code:
sub(Str1,inString(Str1,"(",inString(Str,"(")+1)+1,inString(Str1,"X",inString(Str,"X")+1))2→Str4
TI_Coder wrote:
Ok. I have this line of code which returns a syntax error. I've been looking at these so much, I can't even tell anymore >.<
Code:
Code:
sub(Str1,inString(Str1,"(",inString(Str,"(")+1)+1,inString(Str1,"X",inString(Str,"X")+1))2→Str4
After you get the substring, why are you subtracting 2 from it? You can't subtract numbers from strings.
For reference, this is what your line of code looks like with tabs and newlines added at the parenthesis.
Code:
Code:
sub(
Str1,inString(
Str1,"(",inString(
Str,"("
)+1
)+1,inString(
Str1,"X",inString(
Str,"X"
)+1
)
)2→Str4
I say run a regression on {0,1,2} and seq(expr(Str1),X,0,2) and use a–c under [VARS], 5:Statistics…, EQ. That is, unless you're determined to dissect the expression for its intermediate values, even though they're not needed for this result.
But, here goes:
Code:
Now, what if the user inputs "(2x+3)(5x8)" (with a minus sign)?
But, here goes:
Code:
:DelVar X1+inString(Str1,"+→T
:expr(sub(Str1,Ans,inString(Str1,")")Ans→B
:Ans‾¹expr(Str1→D
:expr(sub(Str1,1,T3→A
:1→X
:expr(Str1)/(A+B)D→C
:{A,B,C,D
Now, what if the user inputs "(2x+3)(5x8)" (with a minus sign)?
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with likeminded coders and tech and calculator enthusiasts via the sitewide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.
» Go to Registration page
» Go to Registration page
» Goto page Previous 1, 2, 3, 4, 5, 6 Next
» View previous topic :: View next topic
» View previous topic :: View next topic
Page 2 of 6
» All times are UTC  5 Hours
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Advertisement