In order to use the function in a spreadsheet, you first need to add a cell that
will be updated by the RTD mechanism. For this we use the built-in Excel
function RTD
. The function's arguments are summarized below.
Argument | Description |
---|---|
progid | The unique program ID of the RTD server module. In our case this is always XllRtdLink.XllRtdSeqNumServer . |
server | The remote machine on which the RTD server is running. We omit this argument, since the server is run locally as an in-process DLL. |
topic1, topic2... | A list of strings which uniquely identify the data which has changed. We only
use one topic, which should match the channel name used in the
worker thread function: i.e. "AvgOpt" . |
Thus we add a formula as follows:
=RTD("XllRtdLink.XllRtdSeqNumServer",,"AvgOpt")
Every time the sequence number of the channel AvgOpt is changed, the cell will automatically update. You should then use it as an input to the cell containing the formula AvgOptValue, so that the cell will automatically be recalculated.
You will remember that we added a new argument to the add-in function AvgOptValue(...)
,
to contain the value of the cell which is updated by RTD. The value itself is
ignored by the add-in function. However, Excel does not ignore it: every time
it changes, the Excel calls the function again.
If the calculation has completed, then the add-in function will now return the result instead of "#WAIT!".
See the sample spreadsheet Samples\AvgOptAsync\AvgOpt.xls
for an
example of this technique in use.
When you use the sample spreadsheet, you will see some major improvements over the original synchronous model: