Hello Guest it is March 29, 2024, 02:42:47 AM

Author Topic: One Macro calling another Macro.  (Read 3457 times)

0 Members and 1 Guest are viewing this topic.

One Macro calling another Macro.
« on: January 01, 2010, 02:48:08 PM »
Please tell how or point me in the direction for some document that explains how one Macro can call another Macro.

Thanks
Re: One Macro calling another Macro.
« Reply #1 on: January 01, 2010, 03:05:25 PM »
Please tell how or point me in the direction for some document that explains how one Macro can call another Macro.

Thanks

There is no document that I'm aware of.  However, all you can do is call M macros, using the Code function.  You cannot call them by name.  And, just to make it more interesting, each M-macro is launched in its own thread, so *you* must provide a mean of synchronization if you require the called macro to complete before the calling macro resumes execution.  This can be done as follows:

Calling Macro:

...
MySemaphore = 1100     ' define Var to be used as semaphore
SetVar(MySemaphore, 1) ' Set the semaphore
Code "M666"                  ' Call my sub-macro
While GetVar(MySemaphore) = 1
    Sleep 100
Wend
...

Called Macro (M666.m1s)

...
' Do whatever we need to do here
MySemaphore = 1100     ' define Var to be used as semaphore
SetVar(MySemaphore, 0) ' Clear the semaphore, telling caller we're done


If you need to "nest" deeper than a single macro, have each calling macro (except the first) increment the Semaphore, and each called macro decrement it when it completes.  The caller must then save the value of the Semaphore *before* incrementing it, and wait for it to return to the saved value, thus ensuring ALL sub-macros have completed.

Regards,
Ray L.

Regards,
Ray L.
Re: One Macro calling another Macro.
« Reply #2 on: January 01, 2010, 03:31:20 PM »
Ray,

Thanks, I will give that a try.

Regards,
Nils