Tips & Tricks

Executing Calculations from VB and VBScript

4 minute read

IntelliCalcs™ is a COM component that can be used outside of IntelliPen to execute either complete or partial calculations or evaluate rules depending upon the evocation. Unless you are simply using EvalFormula to evaluate discrete formulae, it is necessary to have a database with both stored calculations and a mapped data dictionary giving access to data required by the stored calculations. These requirements form the “context” within which the calculation executes.

The examples below are given in VBScript but could equally be used within VB6 or VB.NET assuming that appropriate references to the IntelliCalcs type library are configured.

A simple calculation invocation to determine a single result is as follows:

 

Dim dd ‘As New PCDataDictionary.DataDictionary

set dd = createobject(“PCDataDictionary.DataDictionary”)

dd.Initialise “Provider=SQLOLEDB;Data Source=JUDGES\SQL2005;initial catalog=IntelliPen_Data_Live_20140131;integrated security-SSPI”, “\\Joshua\Inetpub\IntelliSite\system\objects\IntelliPen_DD.xml”

dim personid

personid = 71440

Dim ids1(1, 1)

ids1(0,0) = “EmployeeID”

ids1(1,0) = 80935

ids1(0,1) = “SchemeMemberID”

ids1(1,1) = 71064

Dim ass(1, 0)

ass(0, 0) = “IgnoreFinalYearForGMPCalc”

ass(1, 0) = True

‘dim ids(0)

‘ids(0) = ids1

Dim lResult

Dim FinfCalculation

Set FinfCalculation = CreateObject(“PCCalculationEngine.CalculationEngine”)

FinfCalculation.Loaddata personid, Nothing, Now, “”, ids1, 64, dd

wscript.echo FinfCalculation.CalculateResult(0,”DATA”,”CurrentBenefitName”)

FinfCalculation.FullReset

FinfCalculation.UnloadData

set FinfCalculation = Nothing

Equally to calculate a complete set of results for a calculation type you can use:

Dim dd ‘As New PCDataDictionary.DataDictionary

set dd = createobject(“PCDataDictionary.DataDictionary”)

dd.Initialise “Provider=SQLOLEDB;Data Source=JUDGES\SQL2005;initial catalog=IntelliPen_Data_Live_20140131;integrated security-SSPI”, “\\Joshua\Inetpub\IntelliSite\system\objects\IntelliPen_DD.xml”

dim personid

personid = 71440

Dim garrIDs(1, 1)

garrIDs(0,0) = “EmployeeID”

garrIDs(1,0) = 80935

garrIDs(0,1) = “SchemeMemberID”

garrIDs(1,1) = 71064

Dim arrAssump(1, 4)

arrAssump(0,0) = “InputAVCFundForCash”

arrAssump(1,0) = “0”

arrAssump(0,1) = “InputAVCFundNotForCash”

arrAssump(1,1) = “0”

arrAssump(0,2) = “InputMaxCashRequired”

arrAssump(1,2) = “Y”

arrAssump(0,3) = “InputCashRequired”

arrAssump(1,3) = “0”

arrAssump(0,4) = “InputMaxCLCRequired”

arrAssump(1,4) = “N”

Dim lResult

Dim FinfCalculation

Set FinfCalculation = CreateObject(“PCCalculationEngine.CalculationEngine”)

pc.Calculate personid, arrAssump, CDate(“01/09/2009”), “RETIRE_EARLY”, garrIDs, 65, dd, Nothing

wscript.echo pc.Results.GetResultsXml(0,”RETIRE_EARLY”,””)

FinfCalculation.FullReset

FinfCalculation.UnloadData

set FinfCalculation = Nothing

 

Note that the above code both use the calculation engine for single operations and then close the engine down. To perform a batch of calculations, for example for a group of people inside a loop, the engine can be reused instead of closed down. Instead of FullReset then a Reset should be used within the loop as follows:

Initialise objects outside of loop

Dim dd ‘As New PCDataDictionary.DataDictionary

set dd = createobject(“PCDataDictionary.DataDictionary”)

dd.Initialise “Provider=SQLOLEDB;Data Source=JUDGES\SQL2005;initial catalog=IntelliPen_Data_Live_20140131;integrated security-SSPI”, “\\Joshua\Inetpub\IntelliSite\system\objects\IntelliPen_DD.xml”

Dim FinfCalculation

Set FinfCalculation = CreateObject(“PCCalculationEngine.CalculationEngine”)

Dim garrIDs(1, 1)

garrIDs(0,0) = “EmployeeID”

garrIDs(0,1) = “SchemeMemberID”

For x = LBound(ids,2) to UBound(ids,2) ‘ ids is 2d array of (personid,employeeid,schemememberid)

garrIDs(0,1) = ids(x,1)

garrIDs(1,1) = ids(x,2)

‘assuming no assumptions for calc

pc.Calculate ids(x,0), Nothing, CDate(“01/04/2014”), “TRANSFER_OUT”, garrIDs, 65, dd, Nothing

wscript.echo pc.Results.GetResultsXml(0,”TRANSFER_OUT”,””)

FinfCalculation.lReset

FinfCalculation.UnloadData

Next

FinfCalculation.FullReset

FinfCalculation.UnloadData

set FinfCalculation = Nothing

 

For more complete information on the calculation engine interface please see the IntelliPen Technical Manual pdf.

CalculationType enumeration values:

Estimate = 1

BulkMode = 2

BenefitStatement = 4

NoUserInterface = 8

Recalculation = 16

Projection = 32

DebugRun = 64

FirstPass = 128

TranchingDisabled = 256

CalculateAllResults = 512

RegressionTest = 1024

PerformPosting = 2048