Investment Studio > Views > Macros > Testing

The lower right portion of the Macros view contains a simple spreadsheet which can be used to test macros and built-in functions:

The spreadsheet is essentially a Grid object without database back-end. The cells support the same data types, use the same in-place value editors and display the same error codes as cells in ordinary Grids. The main difference is that you edit individual cell expressions instead of database record definitions, and that there is no need to define any symbols: all cells are automatically named and can be referenced by their coordinates using the familiar "column letter":"row number" form of ordinary spreadsheets (e.g. A1 or B3).

Entering values and expressions

To enter a cell value, all you have to do is select the cell and type away.

If the cell was empty, it will become a float cell provided that the new value can be interpreted as a float, a string cell otherwise. If a cell already has a data type, selecting and then either clicking it or pressing Enter (or just trying to type a value into it) will activate its in-place value editor.

Note that entering a cell value will cause any previous cell expression to be deleted.

The combo box in the spreadsheet's upper left corner shows the data type of the selected cell. Click the spin button to get a drop-down list of all available data types:

Select a different entry in the list to change the data type of all cells in the selected range.

The first entry in the data type list (Empty) is not really a data type at all: it quite literally means that the selected cell is empty (no value, no data type, no expression). Setting the data type of a cell range to Empty is equivalent to pressing Ctrl+Del: all cells in the range will be deleted.
To enter a cell expression, select a cell, then type the expression into the edit box above the cell grid, next to the data type combo box (NOT into the cell's in-place value editor!).

Make sure to start the expression with an equal sign (=) or it will be interpreted as a string value. Hit Enter, doubleclick the edit box or simply exit it to commit to the new expression; hit Esc to discard it and revert to the previous expression (if any).

Handling errors

If you edit an active macro, the modified code becomes available for execution as soon as the editor loses input focus (e.g. when you select a cell in the spreadsheet). The spreadsheet is then automatically recalculated.

If a macro call in a cell expression is returning an unexpected error code (e.g. #VALUE!), look at the "Active macros" page in the editor panel: the location of the last execution error (if any) is highlighted, and the editor's status bar may contain additional information about the problem.
If an error in your macro code causes the ActiveX Scripting engine to become unstable (e.g. causing a scripting error message to pop up or the editor panel's status bar to reflect an abnormal engine state) try restarting the engine using Setup > Engines > Reset in the editor panel's pop-up menu.

If the error persists, disable the package containing the problem macro (uncheck it in the package list).

Navigating & editing

To navigate and edit the spreadsheet, use the mouse, the scroll bars and the following keystrokes:

Up Arrow Select cell one row above current position.
Down Arrow Select cell one row below current position.
Left Arrow Select cell one column left of current position.
Right Arrow Select cell one column right of current position.
PgUp Scroll up one frame. Select cell in corresponding position in new frame.
PgDown Scroll down one frame. Select cell in corresponding position in new frame.
Home Select cell in first column of current row.
End Select right-most non-empty cell in current row. If all cells in row are empty, do nothing.
Ctrl+Up Arrow Scroll up one row.
Ctrl+Down Arrow Scroll down one row.
Ctrl+Left Arrow Scroll left one column.
Ctrl+Right Arrow Scroll right one column.
Ctrl+PgUp Select cell in current column and top row of current frame.
Ctrl+PgDown Select cell in current column and bottom row of current frame.
Ctrl+Home Select cell in upper left corner (A1).
Ctrl+End Select cell in the intersection of the last column and last row containing non-empty cells (note that the selected cell itself may be empty).
Del Reset value of selected cell (to '' for string types, to 0 for numerical types). The cell expression (if any) will be deleted.
Ctrl+Del Make all cells in the selected range Empty (no value, no data type, no expression).
Enter Open the selected cell's in-place value editor, if any.

Note that the spreadsheet allows cell ranges (multiple cells) to be selected. To do so, simply select a corner cell in the range, then drag the mouse to the opposite corner cell. You can then set the data type of the entire range, or delete all cells in it (Ctrl+Del).

You can also select an entire column by clicking the column border; select an entire row by clicking the gray row border; and select all cells in the spreadsheet by clicking the empty corner between column and row borders (just below the data type box).

Example: array passing with VBScript

Consider the following screenshot of the Macros view:

The engine selection box in the view's upper left corner shows that the engine being used is VBScript. Only one package ("array_test") is checked in the package list and hence active. Since it's also the selected package, its contents are displayed in the editor panel. It can be seen to define a function called "dims" which takes a single argument (a).

The function body shows that the input argument a is expected to be a two-dimensional array. The function's result is a one-dimensional array. The first result element contains the size (number of elements) of a along the first dimension; the second result element contains the size of a along the second dimension.

In the spradsheet, the selected cell (C1) can be seen to contain the expression

=dims(a1:b3)

Since there is no built-in function called "dims", this expression causes the dims macro to be executed. The cell range A1:B3 is passed to the macro as the array {{1, 2}, {3, 4}, {5, 6}}.

The value of the first element in the result (3 = number of rows in the argument) is visible in the spreadsheet as the value of cell C1; the value of the second element in the result (2 = number of columns in the argument) is displayed in cell C2 using the cell expression

=index(array(c1), 1, 2)

This result shows that two-dimensional arrays passed to VBScript are indexed as in Investment Studio expressions: rows are the first dimension, columns are the second dimension.