Starting Out

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:

Most of those operations are performed by calling subroutines. All code is heavily commented for easier understanding.