Custom applications and macros

MR_dice_icon.jpg  Download a complete copy of this risk analysis resource for free here.

 There are two versions of this software, and this help file applies to both:

  • ModelRisk Professional Plus - includes the Developer's Tools that allow one to integrate ModelRisk functionality in programming environments like C++, VBA...

  • ModelRisk Professional - this is entirely the same as the Full version, except for the Developer's Tools. If you build your risk analysis models entirely within Excel's spreadsheet environment this version is best suited for you.

 

MR_VBA_1.JPGModelRisk can be used in any programming language that supports calls to DLLs, for example Visual Basic, C++ and Delphi. ModelRisk has a COM-object called ModelRisk Library which is automatically registered in a local system when ModelRisk is installed.

Example: ModelRisk and Visual Basic

To access ModelRisk functions from Visual Basic, for example, one needs to register ModelRisk as a reference for the VB project.

In the Excel VBA editor (brought up with ALT+F11), select Tools from the menu, then References... In the References window presented, mark the ModelRisk Library in the list (see screenshot on the right).

Now when you are writing VBA code, you can call ModelRisk functions, so you can use commands like

x=ModelRisk.VoseNormal(0,2)

To see the available functions in the ModelRisk Library once it is added to the references, open the Object Browser (F2) and then select ModelRisk from the first combo-box.

An example of a VB routine is given below:

Sub TestMR()

' Sample from the bounded Normal(0,1) distribution

Dim Sample As Double

Sample = ModelRisk.VoseNormal(0, 1, , VosePBounds(0.1, 0.9))

' Calculate the combined probability of observing

' the values 125, 112 and 94 from Poisson(100) distribution

Dim Prob as Double

Dim Values As Variant

Values = Array(125, 112, 94)

Prob = ModelRisk.VosePoissonProb(Values, 100, 0)

' Use Central Limit Theorem to sample from the

' distribution of the sum of 120 Normal(25,3) distributions

Dim CLT As Double

CLT = ModelRisk.VoseCLTSum(120, 25, 3)

' Print the output values to the Debug console

Debug.Print Sample, Prob, CLT

End Sub

 

ModelRisk’s COM Object offers a limited number of ModelRisk tools, such as distributions.

The full set of ModelRisk tools is available to programmers in the ModelRisk Dynamic-Link Library (DLL), which allows integrating the full power of ModelRisk into custom, non-spreadsheet standalone applications. For more information regarding the ModelRisk DLL please contact us at info@vosesoftware.com.