Re: Test for existence of a variable?
Re: Test for existence of a variable?
- Subject: Re: Test for existence of a variable?
- From: Michelle Steiner <email@hidden>
- Date: Thu, 11 Aug 2005 07:38:25 -0700
On Aug 11, 2005, at 7:15 AM, Mark J. Reed wrote: DIdn't see anything on this topic in my copy of Neuberg. Is there any way to test to see if a variable has been defined? This code snippet works great if the global variable _ has been assigned a value. If not, however, it fails when I try to save a copy. Is there any sort of test I can use which will test for the variable being defined without blowing up? Or any sort of exception-catching mechanism to intercept the blowup before it happens?
global _ set saved_ to _ (* do stuff with _ *) set _ to saved_
It doesn't blow up for me. When I try to run the script, I get an error at the second line saying that "_" has not been defined. That happens whenever I run the script; before saving, after saving, or after quitting and opening the saved file.
That is how it is supposed to work.
If you are trying to run the script without assigning a value to the variable, then you need to trap the error.
global _ try set saved_ to _ on error number num if num is -2753 then set saved_ to null end if end try (* do stuff with _ *) set _ to saved_
-- Michelle
-- "Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information? Where is the information we have lost in data?"
T.S. Eliot (1915)
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden