Running a Macro in a Macro

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Dman
Junior Coder
Posts: 26
Joined: Mon Apr 21, 2008 2:46 am
Location: Melbourne, Australia

Running a Macro in a Macro

Post by Dman » Tue Jul 01, 2008 5:02 am

I'm sure i've seen topics on this before, but despite numerous searches I cant find anything.. (the search function is a little lacking I've found on previous experience but I have no idea why.)

In any case, I have a series of macros that use the same first 80 lines or so.. and when I tweak those scripts, I dont want to have to manually edit & re-check in 8 different macros. Is there a way I can standardise a particular chunk, maybe read it from a text file dynamically in the macro??

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

Post by Marcus Tettmar » Tue Jul 01, 2008 9:33 am

Yes, use the Include> command, or the Macro> command.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

Dman
Junior Coder
Posts: 26
Joined: Mon Apr 21, 2008 2:46 am
Location: Melbourne, Australia

Post by Dman » Tue Jul 01, 2008 10:27 am

Awesome, thanks for the prompt reply!

asawyer13
Newbie
Posts: 19
Joined: Wed Aug 20, 2008 12:31 pm

Post by asawyer13 » Wed Aug 20, 2008 12:37 pm

I have to read some variables/values from a file that I create (in a different external program).
I am looping thru and each time the values can be different.

Can I use either the include or macro command, and get the variables/values read into my current macro so I can use them, and have it overwrite the old values as I loop thru?

For example, my old scripting tool had a file that you could create that contained
Var1=xyz
Var2=Apple

and by loading it, all the values for the variables would be loaded.

BTW, I am just starting with Macro Scheduler, but in testing the Image Recognition it's much better than the very expensive product I am using now.
I am converting my first macro over tonight.

Thanks,
Alan

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

Post by Marcus Tettmar » Wed Aug 20, 2008 12:42 pm

Can I use either the include or macro command, and get the variables/values read into my current macro so I can use them, and have it overwrite the old values as I loop thru?
Yes, with Include>. No with Macro>

Include pulls the code into the calling macro such that the code becomes a part of the overall macro. Therefore it has access to all variables and can modify them. The included .scp actually becomes part of the overall macro. You will see this in effect if you step past an Include line with the debugger - you'll see the code appear in the editor, and you'll note you have access to all subsequent variables.

Macro> just runs another macro. The calling macro does not have access to the called macros functions or variables. It can pass variables on the command line and can get results back via the MACRO_RESULT variable. But otherwise it is much like running another app with Run>.

If you want access to all the variables, functions etc then use Include>
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

asawyer13
Newbie
Posts: 19
Joined: Wed Aug 20, 2008 12:31 pm

Post by asawyer13 » Wed Aug 20, 2008 12:51 pm

I just want to make sure I understand.

If I do the include, can it be done say once for each loop that I'm working on?

Simple example.
I have a file called File1.scp which has Var1=Apple
I have another file called File2.scp which has Var1=Orange

My macro will be looping thru and the first time will include File1.scp so Var1 will be equal to Apple? During the same processing, I will be looping and including File2.scp so now my Var1 variable with have Orange?

That would work for me, but I'm not sure that's how it really works.

I also will be compiling my main script, so I need to confirm that that would also work.

Basically the files I'm including really are values for different variables depending on what I'm processing in this loop.

Alan

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

Post by Marcus Tettmar » Wed Aug 20, 2008 12:53 pm

Yes, it would work like that. If the included script contains a variable which has already been set by the calling script (or previously included script - same thing) then that variable will change.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

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

Post by Marcus Tettmar » Wed Aug 20, 2008 12:55 pm

Seriously, to visualise what Include does, try it in the debugger. It will become very clear.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

asawyer13
Newbie
Posts: 19
Joined: Wed Aug 20, 2008 12:31 pm

Post by asawyer13 » Wed Aug 20, 2008 12:56 pm

Cool.
I will also look thru debugger. Be gentle, I'm just learning and trying to not head down some dark road that causes me much pain.

I will be working with this tonight.

I am loving Macro Scheduler already.

Alan

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

Post by Marcus Tettmar » Wed Aug 20, 2008 1:02 pm

To visualise:

Imagine you had these two scripts:

File1.scp
Let>Var1=Apple

File2.scp
Let>Var1=Orange

And you had this script:

Include>File1.scp
Include>File2.scp

This is the same as saying:

Let>Var1=Apple
Let>Var1=Orange

Just PASTE the code in the Included file in place of the Include statement. That's all it is doing.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

asawyer13
Newbie
Posts: 19
Joined: Wed Aug 20, 2008 12:31 pm

Post by asawyer13 » Thu Aug 21, 2008 9:58 pm

It doesn't look like the include statement can use a variable name.

Piece of my code, not complete

Code: Select all

   IfFileExists>filenamea
        include>c:\ad1a.txt
      include>%filenamea%

The first include works, but it's hardcoded, the second include says it can't find the file, either with or without the %

I will probably just copy the file to a standard name, and then use it, but it would be nice if the include could have a variable name.

Thanks,
Alan

asawyer13
Newbie
Posts: 19
Joined: Wed Aug 20, 2008 12:31 pm

Post by asawyer13 » Fri Aug 22, 2008 12:27 am

In addition, once the first include statement has occurred, it looks like it destroys the actual include statement so it doesn't replace the old variables with the new ones.

Can anybody tell me how I might be able to get around this?

This is very important so hopefully I can come up with a solution, but I'm a little stumped at this point.

So basically this is my code.

Code: Select all

   IfFileExists>filenamea
      Let>CF_OVERWRITE=1
      CopyFile>filenamea,c:\vars.txt
      include>c:\vars.txt
   End if

Each filenamea file has the variables in it, for example
the first file might have
Let>Name=John

so after the include the variable Name will have John

What I want to do is that when I loop and next the next file
which may have
Let>Name=Joe

I want the variable Name to contain Joe.

It's really pretty powerful if I can get it to work.

Alan

asawyer13
Newbie
Posts: 19
Joined: Wed Aug 20, 2008 12:31 pm

Post by asawyer13 » Fri Aug 22, 2008 1:09 am

I found a post on the forum that showed how to parse out the text file, and with a few modifcations, I was able to get it to work, so I think I'm good.
Thanks,
Alan

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