Does a Control Exist?
Richmond
richmondmathewson at gmail.com
Sun Nov 24 14:55:28 EST 2013
On 24.11.2013 21:37, Ray wrote:
> Really? When I do this...
>
> on mouseUp
> put "test 1" into fld "Cats" -- this field does not
> exist
> put "test 2" into fld "Dogs" -- this field does exist
> end mouseUp
>
> the script editor window pops up on the first line alerting me with an
> error. It never progresses to the second line. I haven't tried this
> in a standalone but I'm pretty sure the script will stop all the same
> just as soon as it encounters the first line.
That WILL halt the script, hence the need to use
if exists(some control) then
do something
end if
checks.
If you try to pour a bucket of water into a non-existent bath-tub you
will get wet feet, at which point
you will be so cheesed-off you will be unable to proceed with whatever
you had planned to do subsequently.
Richmond.
>
> Nonetheless, I'm not all that sure I'm in favor of changing things.
> The idea just occurred to me so I decided to see what other devs on
> the list think about it as long as it's a relatively low traffic Sunday.
>
> Ray
>
> On 11/24/2013 12:27 PM, Richmond wrote:
>> 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.
>>
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
More information about the use-livecode
mailing list