Re: loading a subroutine properly
Re: loading a subroutine properly
- Subject: Re: loading a subroutine properly
- From: Bill Planey <email@hidden>
- Date: Fri, 2 Feb 2001 16:45:25 -0600
Thanks!!! this worked out very nicely. A teentsy gap in my AS knowledge
filled!
Bill Planey
>
On Thu, 1 Feb 2001 17:14:24 -0600, Bill Planey <email@hidden>
>
wrote:
>
>
>Simply because I wanted to modularize part of one of my scripts, I copied
>
>and pasted a certain chunk of code into another compiled script...
>
>
>My subroutine is basically:
>
>
>
>on run
>
>
>
> set handlers -- create variable and declare locations
>
> tell application "Microsoft Word"
>
> do stuff -- using handlers
>
> end tell
>
>
>
>end run
>
>
>
>...and this subroutine is called in the mother script this way:
>
>
>
>load script SubroutineFile -- where the location of SubroutineFile
>
> -- has already been set earlier
>
>
Presuming that the above is what's in the script 'SubroutineFile', then
>
it's not a sub-routine handler, it's a command handler - specifically,
>
the pre defined 'run' handler. If you want to execute this, you have to
>
call 'run script' not 'load script'.
>
>
Unless you really want it this way, it's not the preferred, or at least
>
standard, method.
>
>
Try something like this in your SubroutineFile:
>
>
to doIt()
>
set handlers -- create variable and declare locations
>
tell application "Microsoft Word"
>
do stuff -- using handlers
>
end tell
>
end
>
>
>
Load this into your main script (what you're calling the 'mother') either
>
at compile time:
>
>
property mySubs : load script alias "Path:to:your:file"
>
>
Or at runtime:
>
>
on run
>
set mySubs to load script alias "Path:to:your:file"
>
-- do all your stuff
>
end
>
>
Either way, you'll need to call it like so:
>
>
tell mySubs to doIt()
>
>
Or:
>
>
doIt() of mySubs
>
>
>
To eliminate this requirement, load the script at compile time and
>
declare it as the parent:
>
>
property parent : load script alias "Path:to:your:file"
>
>
>
Now we can call it's sub-routine handler(s) from the 'mother' as if they
>
were in the same file - no tells are required.
>
>
For more info on these techniques, see the ASLG, Chapter 9 - Script
>
Objects.
>
>
I also wrote something a while back (after an edifying discussion here on
>
this topic) which may be of interest to you & others, so I might post
>
that too.
>
>
>
Cheers,
>
>
Richard Morton
>
-- Great Lies of the Music Business: "She'll be backstage after the show"