# Spreadsheet Cell Execution

As with other conventional spreadsheets, the execution order of the cells in the In-Sight spreadsheet is dynamically determined by the relationship and dependencies between cell functions. The In-Sight spreadsheet determines the order of cell execution primarily by evaluating cells according to their dependencies, and secondarily by their locations within the spreadsheet.

### Cell Dependencies

In the following example, the value of cells B2 and A3 directly depend on the value of A2. Cell A4 indirectly depends on A2 because it references A3. Whenever the value in A2 changes, then the values of B2 and A3 must be re-evaluated, followed by A4. An internal execution tree is automatically created to track cell dependencies; this tree is rebuilt whenever the spreadsheet is modified while the system is Offline.

###### Example 1: Simple Dependency Tree

> A2 = 1
> A3 = A2+1
> A4 = A3+1
> B2 = A2+2

When a cell's value or expression changes, the In-Sight spreadsheet locates the cell in the tree and determines which cells need to be re-evaluated. In this example, if the value in A2 changes, then all dependent cells (B2, A3, and A4) must be re-evaluated; however, if the expression in cell B2 changes, then no other cells need to be updated because no cell is dependent upon B2.

### Order of Cell Execution

After dependencies have been evaluated, the cells are evaluated by their location within the spreadsheet. Cells are sorted by their row-coordinate (from left to right), and then by their column-coordinate (from top to bottom.)

### Exceptions to the Cell Execution Order

The following are exceptions to normal cell execution order:

- Clocked functions
- Functions with non-dependency cell-references

In the execution tree, clocked functions are always placed at the top of the tree because they need to access the old data in the other cells.

Several functions take cell references as arguments but do not establish any dependencies. The Row function, which returns the row coordinate of the referenced cell, is one of these functions.

### What Triggers the Execution?

Cells are executed when:

- a cell which has dependents has been modified.
- external events occur, such as triggers.
- Graphics Controls (such as Button, Checkbox, EditInt) signal a spreadsheet event trigger.

Most Vision Tool functions depend either directly or indirectly on the function (Default Cell A0.) Whenever a new image is acquired, these functions execute and return new values. Also, the spreadsheet updates whenever an image acquisition or other spreadsheet event is triggered.