Reusing subroutines across macros

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
aqua267
Junior Coder
Posts: 27
Joined: Thu Aug 19, 2010 7:57 pm

Reusing subroutines across macros

Post by aqua267 » Wed Jan 19, 2011 7:37 pm

I have Macro A that has few subroutines that I would like to reuse in other scripts. For example, Macro A has a subroutine CallSearch. I would like to be able to call the same subroutine from a different macro. The difference is the search keyword I pass.
I tried Include, Macro commands, however they go to the called script and start executing them. I only want them to execute when I explicitly call the subroutine from the calling macro.
How do I do this?

Thanks!

User avatar
Marcus Tettmar
Site Admin
Posts: 7391
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Jan 19, 2011 8:00 pm

Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Post by Jerry Thomas » Wed Jan 19, 2011 10:25 pm

I use this same idea quite a bit. Use a passed parameter to identify the subroutine that is to be called in the first lines of the macro.

Code: Select all

In the main script
Let>MACRO_1=%SCRIPT_DIR%\Macro_1.scp

Macro>MACRO_1 /SubToRun=%SubRoutine_1% /DATA1=%Some_data% /DATA2=%more_data% 

//////////////////////////////////////////////////////////
In MACRO_1

//Call Subroutine passed in from calling script
GoSub>SubToRun,DATA1,DATA2

SRT>Sub1
End>Sub1

SRT>SubToRun
...
End>SubToRun
etc.
You can use MACRO_RESULT to return any values the same way as with a typical macro call.
Thanks,
Jerry

[email protected]

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts