Re: executing blocks of code
Re: executing blocks of code
- Subject: Re: executing blocks of code
- From: Andrew Oliver <email@hidden>
- Date: Mon, 24 Jan 2005 18:57:18 -0800
On 1/24/05 6:35 PM, "Graham Anderson" <email@hidden> wrote:
> I have various functions I have created to try to simplify my code....
> no variables are being passed..they are just executing big blocks of
> code
>
> normally, in my other installer [on the PC] I would use:
> Function myFunction
> ....code
> Function End
>
> when i want to call that function, I just : call myFunction
>
> is there an equivalent in applescript ?
Sure. The equivalent in AppleScript are 'handlers':
on myHander1()
-- code goes here
end myHandler1
on myHandler2()
-- more code goes here
end myHandler2
on run
-- main code that calls other handlers:
myHandler1()
myHandler2()
end run
Note that you can pass parameters to the handlers by declaring them within
the parentheses and passing in the same number of parameters when you call
the handler. Also watch out for scope - variables declared in one handler
are not accessible to other handlers unless they are declared as global.
Finally, for now, handlers can return results back to the caller like:
on getRandom()
set someVar to random number from 1 to 10
return someVar
end getRandom
on run
set randNum to getRandom()
display dialog "Your lucky number is " & randNum
end run
Andrew
:)
_______________________________________________
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