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!
Reusing subroutines across macros
Moderators: Dorian (MJT support), JRL
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Use the Include command. See:
http://www.mjtnet.com/blog/2009/09/09/i ... ary-files/
http://www.mjtnet.com/blog/2009/09/09/i ... ary-files/
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
-
- Macro Veteran
- Posts: 267
- Joined: Mon Sep 27, 2010 8:57 pm
- Location: Seattle, WA
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.
You can use MACRO_RESULT to return any values the same way as with a typical macro call.
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.