Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using mac as a function - returning variables
#1
I like to use
Code:
Copy      Help
mac "Function"
when I can so the function will run asynchronously (in a separate thread) which speeds things up. But when I need a variable returned, I call the function as a function (i.e. without
Quote:mac "..."
.

But I am aware that mac can be used as a function but when I try it, my return variables get messed up:
I know that you have to put in an extra "" for command variable:
Quote:Something to be stored into the _command variable.

Macro MacFunctionTest
Code:
Copy      Help
str Test =  "ooo"
mac "UpperCaseFunc" "" Test
out Test

Function UpperCaseFunc
Code:
Copy      Help
function str&Test
Test.ucase

When I run this I get the following RT error:

Quote:Error (RT) in UpperCaseFunc: invalid pointer. ?

I am not sure if I should be putting the & in front of string references, using lpstr or what?
Any ideas?

Also if in a function I call several other functions as mac, will they not each run in a separate thread (several at a time) or only one at a time?

Code:
Copy      Help
mac "Func1"
mac "Func2"
mac "Func3"
mac "Func4"

The reason I ask is I see this in help menu under "mac":
Quote:Two macros cannot run simultaneously. If both items (this thread and macro) are macros (not functions, etc), macro starts when this thread ends. If only macro is macro, is applied "If a macro is running" property.
S

Thanks,
S
#2
mac "UpperCaseFunc" "" &Test

But it is unsafe if Test is a local or thread variable (not global). If the first thread ends before the second thread accesses the variable, the second thread actually accesses invalid memory location where the variable was, and then exception or memory corruption. Therefore better use global variables.

Quote:Also if in a function I call several other functions as mac, will they not each run in a separate thread (several at a time) or only one at a time?
each run in a separate thread (several at a time).
#3
I would like to call several macros and have each executed one at a time...
How do I go about it?
This is how my current calls look like...
Each macro takes about 3 mins to complete the run but could be longer...

Macro Report NC
Code:
Copy      Help
;---- Recorded 05/04/2014 11:00:58 AM ----
opt slowkeys 1; opt slowmouse 0; spe 100
int w1=act(win("Microsoft Excel - LR Sales" "XLMAIN"))

mac "Spool Arrivals To LR NC Report"
mac "Spool Orders To LR NC Report"
mac "Spool Stock To LR NC Report"
mac "Spool VCC Release To LR NC Report"
mac "Spool Sales To LR NC Report"

opt slowkeys 0; opt slowmouse 0; spe -1
;-----------------------------------------
Best Regards,
Philip
#4
Why don't call as functions?

If want to execute them in other thread, need to wait until the thread ends:
wait 0 H mac("macro1")
wait 0 H mac("macro2")
And they must be functions, not macro. Or Report NC must be function.


Forum Jump:


Users browsing this thread: 1 Guest(s)