Run macro

Syntax

mac[+|-] [macro] [command] [a1 ...]

 

Can be used as function:

int mac([macro] [command] [a1 ...])

 

Parameters

macro - QM item name (full, case insensitive) or id (integer).

command - some string or number. How it is interpreted depends on item type. Default: "".

If macro is command is interpreted as
Macro or function Something to be stored into the _command variable.
Toolbar Window to be associated with the toolbar. Can be window name or handle. If the window does not exist, not error, and the toolbar will not be created.
Menu Menu item label. Instead of showing menu, will execute that item.
Other Not used.

a1 ... - arguments for macro. It receives them through function statement.

 

Options:

Default Run macro.
+ Open macro in editor (don't run).
- End this thread and run macro.

 

Remarks

Launches macro. Unlike function call, macro runs asynchronously, in separate thread.

 

Some features not available in exe.

 

Error if macro does not exist when executing the mac statement. If macro is a sub-function - when compiling.

 

Supported QM item types: all except folders and member functions.

 

mac can be used as function. The return value depends on item type.

If macro is mac returns
Macro or function

Thread handle. You can use it, for example, to wait until the thread ends (see example). Don't close the handle.

Toolbar Toolbar window handle. Read more.
Menu If used as function (like variable=mac("menu")), mac waits until the menu is closed. It then returns a nonzero value if an item clicked, or 0 if not. If used like mac "menu", it does not wait. Read more.
File link Thread handle of function that has "file link run" trigger for that file type.
Other 0

 

If macro and current thread both are macros (not functions etc) without option 'Run simultaneously', macro starts when this thread ends. Then mac returns 0.

 

Note: mac does not wait until the new thread ends. In exe, when the main thread ends, other threads also are terminated. You can use wait 0 H or WaitForThreads to wait for them.

 

Tips

To quickly insert mac statement, you can drag and drop.

 

See also: functions, net, EndThread, RunTextAsFunction, wait for thread (handle), find macro, create macro.

 

Examples

mac "Macro5" ;;run macro "Macro5"
mac "\Folder\Macro5" ;;run "Macro5" that is in "Folder" folder
mac- "Macro5" "a" ;;end current macro and run "Macro5". Also, send string "a" as command.
mac "Func" "" "some string" 1 55.5 ;;run function "Func" and send three arguments
mac "sub.Sub1" ;;run sub-function Sub1 in separate thread

 Get id of "Macro5" and run it:
int i = qmitem("Macro5")
mac i
 
 If window "Notepad" exists, create toolbar "TB" and attach it to the window:
mac "TB" win("Notepad")

 Run function "Function1" in separate thread and wait until it ends:
int hThread=mac("Function1")
wait 0 H hThread

 Call function Function1 (unlike mac, it does not create new thread):
Function1