Comparing variables

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Beginner
Posts: 6
Joined: Thu Aug 15, 2013 7:53 am

Comparing variables

Post by Beginner » Thu Aug 15, 2013 8:05 am

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?

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Comparing variables

Post by Simon » Thu Aug 15, 2013 8:47 am

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Beginner
Posts: 6
Joined: Thu Aug 15, 2013 7:53 am

Re: Comparing variables

Post by Beginner » Thu Aug 15, 2013 10:47 am

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10364
Joined: Wed May 06, 2009 2:28 pm

Re: Comparing variables

Post by dunbarx » Thu Aug 15, 2013 1:55 pm

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

Beginner
Posts: 6
Joined: Thu Aug 15, 2013 7:53 am

Re: Comparing variables

Post by Beginner » Thu Aug 15, 2013 6:52 pm

Oh, I see how I can apply that to my code.
Thanks a lot

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10364
Joined: Wed May 06, 2009 2:28 pm

Re: Comparing variables

Post by dunbarx » Thu Aug 15, 2013 6:57 pm

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

Post Reply