Investment Studio > Views > Macros > Understanding
Investment Studio has a large number of built-in functions for use in custom expressions. It also supports the creation of new functions, known as macros.
From an expression writer's perspective, macros are just like built-in functions. There is only one important difference: while the names of built-in functions are always case insensitive, so that "pi()" and "PI()" always yield the same result, it is possible for macro names to be case sensitive, so that "my_function(1, 2)" will not be equivalent to "MY_FUNCTION(1, 2)".
| Whether macro names are case sensitive depends entirely on the choice of ActiveX Scripting engine. |
To Investment Studio's expression evaluator, any identifier followed by a pair of parentheses, with or without function arguments sandwiched between them, is a function name. When the evaluator comes across a function name which doesn't match any built-in function, it passes the name (just the identifier, up to but not including the parentheses and their contents - argument values are passed separately) "as is" to the selected ActiveX Scripting engine. The engine then looks up the name in its own list of loaded macros. Different engines use different naming conventions. For instance, JScript is case sensitive; VBScript is not. If the name is found, the macro is executed and the result is returned to the expression evaluator.
Arguments to macros are specified according to Investment Studio's usual conventions, just as with built-in functions. The expression evaluator takes care of passing argument values to the engine in a suitable form. Expression writers therefore need not worry about the function call syntax of the language implemented by the engine.
From a macro writer's perspective, macros are ordinary functions written in an ActiveX Scripting language. They receive input data as function arguments, perform internal operations and return output data as function results. Strings and arrays are supported both as arguments and as return values. Investment Studio passes string arguments to macros as OLE strings, array arguments as OLE array, i.e. the native string and array types of VBScript. It also expects strings and arrays returned from macros to be OLE strings and OLE arrays.
See the section on testing macros for an example of array passing.
| Macro writers should avoid all use of global variables, and in particular of assignments to global variables. |
Investment Studio uses a single instance of the selected ActiveX Scripting engine to execute all macros; concurrent calls from objects running in parallel (e.g. multiple charts in the same view) are queued up as they come in and then processed sequentially by the same engine instance. There is therefore no telling whether, and if so how, a global variable might have been modified by other objects between successive calls from a given object.
Detailed information about ActiveX Scripting, including engine downloads and language references, can be found online at Microsoft's MSDN site (search on "scripting").