Newbie question - how to check for a varible

Jim Bufalini jim at visitrieve.com
Fri May 8 03:13:16 EDT 2009


Hi Stephen,

> How do I check if a variable is empty? Sort of like;
> 
> If !empty(tUsername)
>     // process here
> Endif
> 
> Empty() is a Foxpro function that pops if what you are checking is
> empty. I
> can¹t seem to find it¹s equivalent in revolution. Am I approaching this
> the
> wrong way? And can I check fields the same way?
> 
> I suppose I could create an empty variable and just compare the 2? But
> is
> there an easier way?

If tUsername = empty then...
If tUsername is empty then...
If tUsername = "" then...
If tUsername is "" then...

For Boolean:

If tUsername then... true if tUsername is true. False if anything else.
If not tUsername then... true if tUsername is false or empty.
 
> Next question; checking the existence of a variable? Now I know I can
> turn
> on Strict Compilation (and I have) but I¹d rather have the assurance of
> checking to see if a variable exist? Is this a non-issue in Revolution?

Depends on what you mean by existence. ;-) If you have explicit variables on
then you must declare a local variable for the compile to succeed. Script
locals and globals always need to be declared or they will be interpreted as
local. It's good practice to declare all variables to avoid typo errors.

If you want to know if you are using a variable name check out *the
variableNames* and *the globalNames* in the docs. For objects, you can use
syntax like:

If there is a stack/card/button/... or other object name ... "theName" then 
If exists(object) then...

There are lots of options in these areas. They are all well documented in
the docs. ;-) Just keep in mind that in Rev all variables are essentially
strings and so there is not the "type" necessary in other languages. So even
if *if myNumericVar is an integer then...* returns true, myNumericVar is
still a "string." Now as a newbie this can get a little confusing because
the value of a var can be binary and not ASCII. But just think of it as a
"string of bytes" of any type that are in a "container" or are a "chunk" of
bytes. Hint, hint, look up these words in the docs. ;-)

Aloha from Hawaii

Jim Bufalini




More information about the use-livecode mailing list