I have a conditional in my program that I just can't seem to get working right. I've rewrote it several times, but can't think of anything else to try.


Code:

:If sub(Str1,Z,1)="1 and L2(1=-44 or sub(Str1,Z,1)="2 and L2(1)=-44


That's giving me an invalid dim when it comes to it. I tried saying "if the first thing AND the second or the third" but it didn't work (but didn't give me an error). Parenthises didn't seem to work like in other languages.

Btw, this is my first time working with strings. I wouldn't be surprised if it's a string-related problem.
Methinks you should close parentheses and quotes before "and"s and "or"s. Wink
calc84maniac wrote:
Methinks you should close parentheses and quotes before "and"s and "or"s. Wink


Yep, that did it! Thanks. Damn optimizations. Very Happy Oh, well. But is there a way to save a few bytes and only type the "l2(1)=-44" once?

Code:

:sub(Str1,Z,1
:If L2(1)=-44 and (Ans="1" or Ans="2
calc84maniac wrote:

Code:

:sub(Str1,Z,1
:If L2(1)=-44 and (Ans="1" or Ans="2


That's odd. I thought I tried that setup... I must be slipping today. Thanks, again!
You're welcome. Smile

Here's some more optimization:

Code:

:sub(Str1,Z,1
:If -44=L2(1)(Ans="1" or Ans="2
calc84maniac wrote:
You're welcome. Smile

Here's some more optimization:

Code:

:sub(Str1,Z,1
:If -44=L2(1)(Ans="1" or Ans="2
Not sure, but if that doesn't work, you need to add a set of extra grouping parentheses to make it clear that it's implicit AND, not multiplication. In fact, I'm almost sure you do...

Code:

:sub(Str1,Z,1
:If (-44=L2(1))(Ans="1" or Ans="2
The only way -44 can equal L2(1)(Ans="1" or Ans="2") is if:
(Ans="1" or Ans="2") is true
and
L2(1)=-44
which is exactly what it did before, only smaller.
calc84maniac wrote:
The only way -44 can equal L2(1)(Ans="1" or Ans="2") is if:
(Ans="1" or Ans="2") is true
and
L2(1)=-44
which is exactly what it did before, only smaller.
No! Look at the way you have it: first you do Ans = "1" or Ans="2, agreed? Next, it does the implicit multiplication of that times L2(1). Finally, it compares that to -44!! It's all order of operations: comparison generally comes after all arithmetic operations, and ()( counts as implicit multiplication.
Try mine and see for yourself if it works.
calc84maniac wrote:
Try mine and see for yourself if it works.

Yes, it works in this particular case since, for instance, you're testing L2(1) for a nonzero value. It won't work in all situations.
I only meant this particular case anyway.
calc84maniac wrote:
I only meant this particular case anyway.
Fair enough. carry on, then. Smile
I thought using AND anyway is faster than implicit multiplication.
something1990 wrote:
I thought using AND anyway is faster than implicit multiplication.


it is slower than using ' and ', but for whatever reason, people still proclaim the glory of implicit and via multiplication...
I suppose because it's easier to read during debugging. Or else people are trying to be 1337 by using a shortcut. Laughing
Another string related question. How do you replace a character out of the middle of a string? Does it involve the inString command (I'm away from home and don't have my manual)?

:"1"->sub(Str1,4,1 doesn't work...
Say Str1="12345679", and you want to add an "8" between the "7" and "9".

Code:
:sub(str1,1,7)+"8"+sub(str1.8.1 ->str1

Basically take the first section up until immediately before the space where you want to add a character, add the character, and then add the rest of the original string IN THAT ORDER.
Kuro wrote:
Say Str1="12345679", and you want to add an "8" between the "7" and "9".

Code:
:sub(str1,1,7)+"8"+sub(str1.8.1 ->str1

Basically take the first section up until immediately before the space where you want to add a character, add the character, and then add the rest of the original string IN THAT ORDER.


Cool! Thanks, Kuro!
It comes from long experience with strings. Smile
  
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 like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 2
» 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

 

Advertisement