Page 1 of 1
Using an IF statement
Posted: Thu Sep 12, 2013 4:43 am
by shawnblc
Should be getting my book, Programming LiveCode for the Complete Beginner in about a week.
In the meantime...I'm still having issues wrapping my head around a good portion of LC. Example below, in which I'm having issues and don't see where I'm going wrong.
Code: Select all
on mouseUp
if fld fldEmail = "fldEmail" then // i have an input box named fldEmail and in my db i have the same field with an email in it.
go to stack url "http://domain/1.livecode"
else
go to stack url "http://domain/5.livecode"
end if
end mouseUp
Re: Using an IF statement
Posted: Thu Sep 12, 2013 5:39 am
by dunbarx
Hi.
There is nothing syntactically wrong with your handler, though I would always put object references in quotes (fld "fldEmail")
The handler did not download a stack, though. Is that what you are asking about? The dictionary states that:
If you specify a URL, the stack is downloaded from that URL and displayed. The stack must be in stack file format (that is, not compressed or archived). Stacks opened in this way are treated as unsaved stacks; the long name of such a stack is the same as its abbreviated name, until the stack is saved on a local disk. The downloaded stack is a copy: changes you make to the stack are not automatically made on the server the stack came from. To change the stack on the server, you must save the stack file locally and re-upload it.
Craig Newman
Re: Using an IF statement
Posted: Thu Sep 12, 2013 5:40 am
by shawnblc
It's always downloading 1.livecode. Instead of when the email doesn't match downloading 5.livecode.
Re: Using an IF statement
Posted: Thu Sep 12, 2013 6:09 am
by dave_probertGA6e24
Hi,
Try this and see what happens:
Code: Select all
on mouseUp
if fld "fldEmail" is "fldEmail" then
go to stack url "http://domain/1.livecode"
else
go to stack url "http://domain/5.livecode"
end if
end mouseUp
It might work - or not!
Re: Using an IF statement
Posted: Thu Sep 12, 2013 6:16 am
by shawnblc
dave_probertGA6e24 wrote:Hi,
Try this and see what happens:
Code: Select all
on mouseUp
if fld "fldEmail" is "fldEmail" then
go to stack url "http://domain/1.livecode"
else
go to stack url "http://domain/5.livecode"
end if
end mouseUp
It might work - or not!
Same thing. Always goes to 1.livecode. No matter what the email. In the database I have two different emails, one for each card. Doesn't matter what I put in the field always 1.livecode.
Re: Using an IF statement
Posted: Thu Sep 12, 2013 7:00 am
by Simon
I think there is much missing here.
The whole DB thing is questionable, not sure:
...in my db i have the same field...
What is a "field" in a DB?
Now, if you said you extracted the DB data into a liveCode field and then do your comparison then there is a start.
Simon
Re: Using an IF statement
Posted: Thu Sep 12, 2013 8:51 am
by dave_probertGA6e24
Hi,
Time to do some debugging...
Code: Select all
on mouseUp
put fld "fldEmail" into xxxxx
put "FLD EMAIL:" && xxxxxx into msg
if xxxxx is "fldEmail" then
...
in the messagebox you should see what it thinks is in fld "fldEmail".
It'll probably help you a bit.
Cheers,
Dave
Re: Using an IF statement
Posted: Thu Sep 12, 2013 9:04 am
by AndyP
Hi, try adding an extra field "EmailfromDatabase" so you can see better what is being retrieved from the database then compare the two fields.
on mouseUp
put fldEmail into fld "EmailfromDatabase" // add new field for testing so that you can see what is actually being retrieved from the database.
if fld "fldEmail" = fld "EmailfromDatabase" then // i have an input box named fldEmail and in my db i have the same field with an email in it.
go to stack url "
http://domain/1.livecode"
else
go to stack url "
http://domain/5.livecode"
end if
end mouseUp
Re: Using an IF statement
Posted: Thu Sep 12, 2013 4:45 pm
by Klaus
HI shawn,
Andy is 100% correct!
All the time you are checking the content (text) of your field "fldEmail" againt the STRING (text) "fldEmail"
but you aren't referencing the actual value from that field in your database!
Best
Klaus