• 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: variables vrs properties
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: variables vrs properties


  • Subject: Re: variables vrs properties
  • From: Luther Fuller <email@hidden>
  • Date: Thu, 06 Jan 2011 11:20:41 -0600

On Jan 6, 2011, at 9:57 AM, KOENIG Yvan wrote:

I apologizes but I disagree with the sentence :

Any variable used in the run handler (implicit or explicit) is automatically global. 

Look here:

on run
try
set une_variable to 123
my main()
on error errText number errNr
if errNr = -128 then
return
else if errNr = -2700 then
tell application "Mail" to display dialog errText buttons {"OK"} default button 1
else
"Error = " & errNr & return & errText
display dialog the result buttons {"OK"} default button 1
end if
end try
end run -------------------------------------------------------

on main()
set une_variable to une_variable + 1
end main -------------------------------------------------------

If you run it you will get an error message because une_variable  
which is defined in the run handler is local to this one 
and is not seen by the handler main().

In the handler main, une_variable is undefined only because it does not contain the line

global une_variable

which imports it into this handler. But, in the run handler, une_variable is a global variable.

Compile this as an application, then run it multiple times ...

on run
try
set une_variable to (une_variable + 1)
on error
set une_variable to 123
end try
display dialog une_variable
end run

The variable is clearly global.

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Re: variables vrs properties (From: Jim Brandt <email@hidden>)
 >Re: variables vrs properties (From: Luther Fuller <email@hidden>)
 >Re: variables vrs properties (From: KOENIG Yvan <email@hidden>)

  • Prev by Date: Re: variables vrs properties
  • Next by Date: Re: variables vrs properties
  • Previous by thread: Re: variables vrs properties
  • Next by thread: Re: variables vrs properties
  • Index(es):
    • Date
    • Thread