The sample code in OptDevKitRuntimeSample.xls begins by explicitly declaring variable types for several variables:
Option Explicit Private WithEvents PortfolioOptRuntime As CBCOMDevKit.OptRuntime Private PortfolioOptSetup As CBCOMDevKit.OptSetup Private ObjectiveTotal As CBCOMDevKit.Objective Private RequirementRisk As CBCOMDevKit.Requirement Private ConstraintFunds As CBCOMDevKit.Constraint Private DecisionFund1 As CBCOMDevKit.Decision Private PortfolioWorkbook As Workbook Private InvestmentModel As Worksheet Private Options As CBCOMDevKit.OptOptions
Next, it opens the subroutine that actually performs the optimization and defines error handling:
Sub RunOptimization(RunEF As Boolean) On Error GoTo ErrorHandling
From there, it creates (instantiates) Setup and Runtime objects and resets the optimization:
Set PortfolioOptSetup = New CBCOMDevKit.OptSetup Set PortfolioOptRuntime = New CBCOMDevKit.OptRuntime PortfolioOptRuntime.Reset
This subroutine goes on to:
Close any open worksheets
Create a new Portfolio Allocation workbook
Clear any previous OptQuest data
Select a primary workbook for optimization
Set up the investments
Set up the optimization
Set up Efficient Frontier analysis, if requested
Configure any options
Run the optimization, show the Control Panel
Get and display the optimization results
Modify the OptQuest Results window display
Most of those operations are performed by calling subroutines. All code is heavily commented for easier understanding.