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

Re: global variables


  • Subject: Re: global variables
  • From: Stan Cleveland <email@hidden>
  • Date: Wed, 17 Jul 2013 13:48:23 -0700

On Jul 17, 2013, at 1:27 PM, Kaydell Leavitt wrote:

I tried a global variable with the following code.

global x
set x to 2
set x to x + 1
display dialog "x: " & x

It always displays 3 as the result.

Hi Kaydell,

Yes, it always displays 3, because you redefine x each time the script is run. 
Try this version, which defines x only during the first run:

global x
try
x
on error
set x to 2
end
set x to x + 1
display dialog "x: " & x

Stan C.

 _______________________________________________
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: 
 >global variables (From: Jim Brandt <email@hidden>)
 >Re: global variables (From: Luther Fuller <email@hidden>)
 >Re: global variables (From: Kaydell Leavitt <email@hidden>)

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