Does a Control Exist?

Richmond richmondmathewson at gmail.com
Sun Nov 24 12:27:01 EST 2013


On 24.11.2013 18:58, Ray wrote:
> Yeah, I know there are various ways of checking whether the control 
> exists or not before proceeding.  I just wondered whether anybody else 
> thought it might be nice not to have to do that since it does halt the 
> script if the control doesn't exist.
>
>> Well, surely the trick is to do something like this:
>>
>> if exists(fld "My Field") then
>>     put fld "My Field" into myVar
>> end if
>>
>> Easy-Peasy-Lemon-Squeezy!
>>
>> Richmond.
>>

I must be missing something . . .

I'm not sure what you mean by "halt the script".

Certainly, if fld "My Field" does not exist the script won't put 
anything into myVar, after all, it's
not meant to.

I just tried something else, in an attempt to understand what you meant 
by "halt the script";

I set up a stack with one fld "cheese" and a one btn "Button" containing 
this script:

on mouseUp
    if exists(fld "dogs") then
       put "yap" into fld "dogs"
    end if
    if exists(fld "cheese") then
       put "zip" into fld "cheese"
       end if
end mouseUp

Now, as fld "dogs" does not exist, "yap" appears nowhere, but "zip" does 
end up in fld "cheese";

so the fact that fld "dogs" does not exists does not stop the rest of 
the script from doing what it should.

Richmond.




More information about the use-livecode mailing list