checking for empty field

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
tyarmsteadBUSuSfT
Posts: 151
Joined: Sat Aug 25, 2012 1:14 am

checking for empty field

Post by tyarmsteadBUSuSfT » Sun Feb 10, 2013 9:08 pm

I'm having a brain fade. I want to Get the info in a field and put it into a variable. Then if that field is blank or empty, use the if option to decide the next course of action. However when I Get the field then put it into a variable or just use the "it" result I have the problem. If the "it" or the variable is empty I can get the If tVariable is Empty then... to work. I've tried If tVariable is "" then, If tVariable is not text then...
Fo illustration purposes I am using tVariable.
Thank you,

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: checking for empty field

Post by sturgis » Sun Feb 10, 2013 10:22 pm

You can check the field directly..
if field "fieldname" is empty then

else

end if

Or skip get and put the contents right into your variable

put field "fieldname" into tVariable
if tVariable is empty then

else

end if


Using get you can

get field "fieldname"
if it is not empty then
put it into tVariable
else
-- it was empty..
end if

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

Re: checking for empty field

Post by dunbarx » Sun Feb 10, 2013 11:09 pm

Hi.

What Sturgis said.

But where are you getting that brain thing? Is it that you do not trust the fact that if nothing is in your variables (whichever they are), then you are not sure that means its value is empty? If so, I sort of get that. Practice for a while and it will go away. Empty means just that, no content, a string of zero length (though not "0" per se).

You can always test, and I think you already did:

if yourVariable = empty then beep 3 --or whatever

This is more useful than you might think. There are many times when a field, say, looks empty, but is not. It might contain return or tab characters, for example.

Your question is very reasonable. Did I mention to practice?.

Craig Newman

Post Reply