• 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: "email@hidden" <email@hidden>
  • Date: Thu, 6 Jan 2011 09:46:41 -0800

Look here:

on run
try
set une_variable to 123
my main()
display alert une_variable
on error errText number errNr
"Error = " & errNr & return & errText
display dialog the result buttons {"OK"} default button 1


end try
end run -------------------------------------------------------


on main()
global une_variable
set une_variable to une_variable + 1
end main ------
-----
Any variable in a run handler is global and acts like a global, not a property, so you must declare it inside the handler to access its value in the handler.

That applies to run handlers, including implicit run handlers. It does not apply to open handlers. Globals must be declared inside the open handlers.

ES


On Jan 6, 2011, at 7:57am, KOENIG Yvan wrote:


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().

 _______________________________________________
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: Slow vs faster
  • Previous by thread: Re: variables vrs properties
  • Next by thread: Re: variables vrs properties
  • Index(es):
    • Date
    • Thread