Comparing variables
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Comparing variables
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?
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
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
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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Comparing variables
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
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
Here is a case where you have to be careful when comparing strings. I leave this to you:
Craig Newman
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
Re: Comparing variables
Oh, I see how I can apply that to my code.
Thanks a lot
Thanks a lot
Re: Comparing variables
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
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