XLL+ Class Library (6.3)

AvgOptAsync2 Sample

An option value calculator add-in, which runs lengthy calculations in a background thread

Overview

This add-in contains a calculator for calculating the value of a complex option. The hand-written code is identical to that in the single-threaded sample AvgOpt.

The calculation of the option value is very slow (since it uses a Monte-Carlo algorithm) and it may therefore be worthwhile running the calculation in a background thread. Excel remains fully available and responsive while the calculations run.

The spreadsheet is only updated when a calculation has finished, and the results are available. Until the calculation completes, the result #WAIT! is displayed.

Significant steps

The significant steps in producing this sample were:

  1. When creating the project in the XLL+ AppWizard, the features "Support asynchronous functions" and "Include a cache for results" were checked.

  2. The function AvgOptValue was edited in the XLL+ Function Wizard, and a check was put against "Create asynchronous version" (on the "Features" tab).

Details

More details of this sample are contained in the User Guide topic Asynchronous functions.

Classes and functions used

CXlOper::Ret | CXlMenu | CXlMenu::SetTexts | CXlMenu::AddItem | CXlMenu::Create | CXlMenu::Destroy | CXllApp::WinMessageBox | ::XllGetTypedApp

Sample project

Each sample project is located in a sub-directory of the Samples directory of the XLL+ installation. To use the sample project, open the solution file AvgOpt.sln or the project file AvgOpt.vcproj.

You can enable debugging under Excel by using the Setup Debugging command in the XLL+ ToolWindow.

When delivered, the help files are excluded from the build. You can enable the help build by selecting the files AvgOpt.help.xml and AvgOpt.chm in the Solution Explorer, and using the right-click menu to view Properties. Select the page "Configuration Properties/General" and set the "Excluded from build" property to "No". See Generating help in the User Guide for more information.

See Also

List of Sample Projects