• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Question about handler
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about handler


  • Subject: Re: Question about handler
  • From: Graff <email@hidden>
  • Date: Fri, 02 Apr 2004 13:39:14 -0500

On Apr 2, 2004, at 10:51 AM, Robert Poland wrote:

You can set pictureCount as a global variable. Do this at the top of the script:

global pictureCount

The values of global variables are saved between runs so it is a good idea to initialize them to clear any retained values that might mess up your calculations. You are doing this in the open handler already so this shouldn't be a problem.

- Ken

Is there a way to clear a variable like in C?
i.e. global pictureCount ()

You can't really clear a variable in C, all you can do is to set it to a different value. Maybe one that is as neutral as possible, such as zero for an int or NULL if it is a pointer. This is pretty much true also with AppleScript. I do believe there is a hidden null value in AppleScript that you can invoke but usually it's not needed and it's not always a good idea to do.

However, remember that variables in AppleScript aren't stuck to one type like those in C. So you can set the variable to something else that is blank, for example:

set pictureCount to ""

or

set pictureCount to {}

There is also a predefined constant which is designed for you to set a variable to so that you can tell it hasn't been accessed yet. That constant is "anything":

set pictureCount to anything
-- do some stuff
if pictureCount is anything then set pictureCount to 0

There is also the "missing value" constant which is returned when a variable doesn't have a value. I believe it can be used in the same way as the "anything" constant:

set pictureCount to missing value
-- do some stuff
if pictureCount is missing value then set pictureCount to 0

You can read more about these constants here:
<http://developer.apple.com/documentation/AppleScript/Conceptual/ AppleScriptLangGuide/AppleScript.45.html>

In a script such as the one in the e-mail that I replied to it's enough just to explicitly set the variable to zero at the start of the script.

- Ken
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.


References: 
 >Question about handler (From: stephan <email@hidden>)
 >Re: Question about handler (From: Graff <email@hidden>)
 >Re: Question about handler (From: Robert Poland <email@hidden>)

  • Prev by Date: Re: Quark - setting justification dynamically
  • Next by Date: Re: Mac Mail Questions
  • Previous by thread: Re: Question about handler
  • Next by thread: Saving Entourage Attachment solution
  • Index(es):
    • Date
    • Thread