Page 1 of 1

Comparing variables

Posted: Thu Aug 15, 2013 8:05 am
by Beginner
Hi everyone,
I am working on an code to check for errors, a simplified example is this:

get shell ("echo hello")
put it into h
answer h = "hello"

I am trying to take an error and match it to an appropriate hard coded string so that the program can respond accordingly.
However, it always returns "false" even though the words in the variable inside match.
Can you guys help?

Re: Comparing variables

Posted: Thu Aug 15, 2013 8:47 am
by Simon
Hi Beginner,
Welcome to the forum :)

Why are you using "answer" when the "it" variable contains what you want?
As you say "...the words in the variable inside match".

Simon

Re: Comparing variables

Posted: Thu Aug 15, 2013 10:47 am
by Beginner
Hi Simon,
I put "answer" because I wanted to check if the variable values match (answer displays "false"), however, that should not be the case as the variable values should match and "answer" should display true

Re: Comparing variables

Posted: Thu Aug 15, 2013 1:55 pm
by dunbarx
Here is a case where you have to be careful when comparing strings. I leave this to you:

Code: Select all

on mouseUp
   get shell ("echo hello")
   put it into h
   answer h && the length of h && charTonum(the last char of h)
end mouseUp
Craig Newman

Re: Comparing variables

Posted: Thu Aug 15, 2013 6:52 pm
by Beginner
Oh, I see how I can apply that to my code.
Thanks a lot

Re: Comparing variables

Posted: Thu Aug 15, 2013 6:57 pm
by dunbarx
Good.

I do not know why a trailing return comes back with the shell request, but it is a good lesson. When something looks like it ought to work but does not, check out invisible culprits.

Craig Newman