Macro Editor

The Macro edit table is used to assign recurring text to a reference name.

 

ID A name to identify the macro.

Text Any text to be substituted where the macro name is called. This text may be a complete expression, an entire logic block, or even part of a logic block.

Options Allows you to define the macro as a run-time interface parameter or select a resource group.

The example table above defines three macros. The first macro is simply a numeric constant, with fpm representing a conversion factor from miles per hour to feet per minute. If a number is used in multiple places in a model, then a macro makes it possible to change that number throughout the model simply by changing the macro itself. The second macro, Operation_Time, calculates the various operation times at different locations depending on the attributes at the locations. The last macro, Number_of_AGVs, is a run-time interface variable used to define the number of AGVs in the simulation model. See Run-Time Interface for more information.

A macro is different from a subroutine because a macro cannot pass or return a value. However, because it is simply a text replacement, a macro can reference any expression valid in the expression or logic field that called the macro. For instance, the string "the number of entries is" might be a macro called mac1. This macro by itself is not a valid expression. However, when used with the DISPLAY statement in the operation logic (i.e., DISPLAY mac1), the compiler will recognize the macro as a string.

A macro may be used in any expression field, but may only contain a numeric expression (e.g., Entries (LOC1), U(5,1), Var1+Att2, etc.). In addition, a macro used in an expression field may not contain multiple lines of text. When used in a logic field, the macro may include any logic element valid in that logic field.

Suppose five different locations use the same lines of code. Instead of entering the same logic five times in five different fields, reference the following macro by typing the macro ID, Mac1, in the operation logic of the machine:

 

Every time the macro is referenced, the logic is executed. Macros can also be nested within other macros. This means that a macro can consist of one or more other macros. Consider the following Macro edit table:

 

The macro, Favorite_Quote references other macros, such as Race and Finish. Note that some of the other macros, such as For_Quality, are only portions of a complete line of code. Although the macro is valid, it will not compile as a part of macro logic because the create statement requires an expression and an entity name. The line Favorite_Quote in a logic field would be interpreted as the following line, Create 2 As EntB Take 1 Res1.

Please note

Macro notes:

1. A macro may be used only when the elements contained in the macro are appropriate to the context from which it was called. This restriction means that the macro in the previous example is only valid in operation logic.

2. Because a macro simply substitutes some text for its name, if a macro represents a statement block, then it should contain a BEGIN at the beginning of the block, and an END at the end of the block. This technique is especially important when using a macro immediately after a control statement, such as IF...THEN or WHILE...DO. For more information, see Statement Blocks.