Can i run a macro(sub) within a macro(main) and get the output variable of the macro(sub)? like this...
function Main(){
macro sub.mac
string data = data_from_sub
PRINT $data
}
then my standalone macro
function Main(OUTPUT string data_from_sub){
string data_from_sub = "hello world"
use:
MACRO "C:\folderwithmacros\AnOther.mac"
to run a macro from another one. change address as your macro
you could do it like this:
first file with the main macro:
include "yourfunctionspath\functions.inc"
function main() {
//main mac
string $data_from_sub = ""
call myExternFunction($data_from_sub)
message info &data_from_sub
}
the second file with the method called in the first one:
function myExternFunction(output string $data_from_sub) {
$data_from_sub = "data"
}
I like to use project variables if I am passing data from one macro to the next, but usually this is when I have separate macros that are not sub macros. If I wanted to do a sub macro call, but pass data back, I'd just rewrite the sub macro as a function in the main macro or do as @icse suggested.
But that said, project variables will work with sub macros like this:
// Main macro
FUNCTION Main() {
macro sub.mac
// safety check to make sure sub macro ran properly
if not member($Project._keys, "Data") {
message info "data from sub macro not found."
} else {
message info $Project.Data
}
}
// Sub Macro
FUNCTION Main() {
string data_from_sub = "data"
// Create project variable if it doesn't exist
IF NOT Member($Project._keys, "Data") {
EDIT USERPAR project NAME "Data"
EDIT USERPAR project TYPE 'String'
CREATE USERPAR project
}
$project.Data = $data_from_sub
}
And if you don't want tons of project variables or don't need them after using them then you can always delete it after use with this:
EDIT USERPAR project SELECT "Data"
DELETE USERPAR project SELECTED
Can't find what you're looking for? Ask the community or share your knowledge.