Equinox Online Help - Language Reference - A to Z

Home

ExecuteMacro

Applies to
SyntaxExecuteMacro SourceCode [,How]
Action[Statement] Allows source code to be written and executed under program control.
ScopeUsable anywhere
Notes

The text in SourceCode is compiled and executed as method language at run-time.

This enables complex method language to be built up, perhaps according to user input, and then executed. Application uses might be to build up search/ filter statements, or to allow the user to specify at run-time what they want in a report.

The optional parameter [,How] can take the following values:

  • 0 The macro executes in its own separate subtable block and no errors are reported
  • 1 As above, but errors are reported in the print window.
  • 2 The macro executes as part of the current subtable block, if any, without error reporting.
  • 3 As above, and errors are reported in the print window.
Accessing fields and workareas from within macros

Normally Equinox knows when a method executes which fields will be referred to, and builds a list when the method is saved. In macros, the same process occurs at runtime, before the macro is executed. Equinox creates a list of items that will be referenced, including information about the current record and so on.

Normally this information is separate from the list held for the calling method, in a similar way to separate subtable blocks. This means that if you write to fields inside a macro executed with How set to less than two, the field values will not affect those in the calling method.

If How is two or greater, Equinox uses the list from the calling method, and so the new values are preserved. However if you try to access fields or workareas which have not been referenced outside the macro, an error will occur, as Equinox is not able to create references to new items inside the macro.

CategoryFlow Control
See Also Block_EndBlock, BreakPressed, Continue, Execute, EnableInput, Exit
Example

The following example shows how a simple filter is created according to user choices. Note also the use of the multi-line string character $...$

memo vMethod
string vField,vCondition,vValue,vTable,vQIndex,vTest

PopupSize ,,40
PopupSize ,,40
vField = Input("Enter field to filter on:",true)

PopupSize ,,40
vCondition = Input("Enter condition (eg,>,<,<>):",true)

PopupSize ,,40
vValue = Input("Enter value:",true)

PopupSize ,,40
vQIndex = Input("Enter query index to fill:",true)

vTest = "If " & vField & vCondition & vValue & " then markindex " & vQIndex

vMethod = "Subtable " & vTable & $
Firstrecord
BlankIndex $ & vQIndex & $

while not syserror
$ & vTest & $
nextrecord
end while
end subtable
$

Print "Executing Macro";;vMethod

ExecuteMacro vMethod

if SysError then
Alert "Invalid options specified!"
else
Alert "Filter complete"
end if