Skip to main content

#execute

Executes a line of ObjectScript at compile time.

Description

This macro preprocessor directive executes a line of ObjectScript at compile time. It has the form:

#execute <ObjectScript code>

where the content that follows #execute is valid ObjectScript code. This code can refer to any variable or property that has a value at compile time; it can also invoke any method or routine that is available at compile time. ObjectScript commands and functions are always available to be invoked.

#execute does not return any value indicating if the code has successfully run or not. Application code is responsible for checking a status code or other information of this kind; this can use additional #execute directives or other code.

Note:

There may be unexpected results if you use #execute with local variables. Reasons for this include:

  • A variable used at compile time may be out of scope at runtime.

  • With multiple routines or methods, the variable may not be available when referenced. This issue may be exacerbated by the fact that the application programmer does not control compilation order.

For example, you can determine the day of the week at compile time and save it using the following code:

#execute KILL ^DayOfWeek
#execute SET ^DayOfWeek = $ZDate($H,12)

 WRITE "Today is ",^DayOfWeek,".",!

where the ^DayOfWeek global is updated each time compilation occurs.

FeedbackOpens in a new tab