how to call subroutine from another

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
ruchi
Newbie
Posts: 9
Joined: Thu May 13, 2010 3:08 am

how to call subroutine from another

Post by ruchi » Fri Jun 11, 2010 6:20 pm

I have couple of subroutines that are actively used in my 10 other scripts. currently I have copied the subroutine into all my 10 scripts. Is there a way if I have macro script -1 that has SRT1, how can I call this SRT1 from macro script 2, macro 3 etc?

Thanks

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Fri Jun 11, 2010 6:52 pm

Would this help you?

Include>scriptfile

Includes code from an external script file. The code is executed and made available to the calling script. Therefore variables and subroutines in the external script file are made available to the calling script.

ruchi
Newbie
Posts: 9
Joined: Thu May 13, 2010 3:08 am

Post by ruchi » Fri Jun 11, 2010 9:08 pm

Say for example:
macroscript1:
SRT1>....
SRT2>....
SRT3>....
SRT4>....

macroscript2:
SRT-A>...
SRT-B>...
SRT2>....
SRT4>.....
now macroscript2, needs only subroutines 2 and 4 from script 1. how could I do this?

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Fri Jun 11, 2010 9:28 pm

Put each subroutine that you want to share between scripts into it's own separate file.

Example:

c:\srt2.scp
---------------------------
SRT>mySub2
... code goes here
... more code
END>mySub2


Then from macroscript1
SRT>Sub1
END>Sub1

Include>c:\srt2.scp

SRT>Sub3
END>Sub3


Then from macroscript2

Include>c:\srt2.scp

SRT>Sub4
END>Sub4

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri Jun 11, 2010 10:03 pm

You could also include> script 1 (the file that has the four subroutines) then only use Gosub> to call subroutines 2 and 4. As long as the subroutines all have unique names, there is no real problem having subs 1 and 3 resting quietly and unused in your calling script.

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