Log in | Register



Model vs Results

Some uses of Resolver One, in particular, updating cell values from user code, make it important to understand the distinction between the spreadsheet ''model'' and ''results''.

What are the model and results?

The model is comprised of all the constants and formulae typed into cells, together with the user code typed into the codebox. These items define the core of the numerical model that is a Resolver One spreadsheet document.

The results are derived from the model, by evaluating all the cell formulae, and executing all the user code. The resulting values are displayed in the cells of the grid. Although derived from the model, these results are transitory, as results are thrown away and regenerated from the model at every recalculation.

Updating cells from user code

Updating cell values from user code is done by assigning values to cell objects, which are obtained from the document's workbook object. Modifying this workbook object will only affect the displayed results, not the underlying model.

This can be demonstrated by typing a value, for example '42', into cell B2, and then attempting to change that value with the following user code:

sheet = workbook["Sheet1"]
sheet.Cells.B2.Value = 'foo'

Placing this in the pre-constants user code will not have the desired effect. The grid still displays '42' in cell B2. This is due to the value in B2 being overwritten after the above code, by the generated code in the 'constants and formatting' section, which overwrites cell B2 with the value '42', from the model.

Placing the above code in the post-formulae user code is a little better. This changes the value displayed in the grid - it now shows 'foo' instead of 42. However, there is still a problem, in that cells which reference B2 will not see the new value of 'foo'. This can be demonstrated by typing '=b2' into cell C2, which will display the old value of '42'.

Placing the above code in the pre-formulae user code has the best result in this instance. The grid now displays 'foo' in B2, as do cells like C2 that reference it.

However, the '42' stored in cell B2 of the model is still lurking in the background, and this wrinkle can become visible in some circumstances, such as in the formula bar if you click on cell B2. Also, using copy and paste transfers values from the underlying model, not the results, and so copying B2 will copy the underlying '42', without the 'foo'.

Comments