APISynthesisResourcesTutorial4

 << Back to Quick Start Guide

Synthesis Resources Tutorial
 * 1) Connect to a Synthesis Repository and Project
 * 2) Create a New Synthesis Resource
 * 3) Update an Existing Resource
 * 4) Calculate Results from a Model

Models are used by other Synthesis resources to represent the reliability of a task, the duration of a task, the expected cost of a repair, and many other characteristics. In this section, we'll learn how to obtain calculated results from models.

Part 4: Calculate Results from a Model
1. Create a new module, and then add code to retrieve the model that we've been working on in the previous sections (recall that the model's name is now "MyNewModel_Update"). The following code example assumes that the model's ID number is 21.

VBA MyRepository Repository MyRepository.ConnectToRepository MyRepository.Project.SetCurrentProject(1) AModel cModel AModel = MyRepository.Model.GetModel(21)

VB.NET MyRepository Repository MyRepository.ConnectToRepository MyRepository.Project.SetCurrentProject(1) AModel cModel AModel = MyRepository.Model.GetModel(21)

2. Use the  method to calculate for the reliability at 100 hrs and the   method to return the mean time to failure.

VBA|VB.NET Result1 Double Result2 Double Result1 = AModel.Reliability(100) Result2 = AModel.MeanTime

3. Let's add confidence bounds calculations to the results. Use the  method to specify 90% two-sided confidence bounds.

VBA ErrorMsg String AModel.SetConfidenceLevel(0.9, ConfBoundsSides_TwoSidedBoth, False, ErrorMsg) BResult1 BoundsValues BResult2 BoundsValues BResult1 = AModel.Bounds_Reliability(100) BResult2 = AModel.Bounds_MeanTime MsgBox ( & Result1 & vbNewLine & _           & BResult1.upper & vbNewLine & _            & BResult1.lower & vbNewLine) MsgBox ( & Result2 & vbNewLine & _           & BResult2.upper & vbNewLine & _            & BResult2.lower & vbNewLine)

VB.NET ErrorMsg String AModel.SetConfidenceLevel(0.9, ConfBoundsSides.TwoSidedBoth, False, ErrorMsg) BResult1 BoundsValues BResult2 BoundsValues BResult1 = AModel.Bounds_Reliability(100) BResult2 = AModel.Bounds_MeanTime MsgBox ( & Result1 & vbNewLine & _           & BResult1.upper & vbNewLine & _            & BResult1.lower & vbNewLine) MsgBox ( & Result2 & vbNewLine & _           & BResult2.upper & vbNewLine & _            & BResult2.lower & vbNewLine)

Test the Code
Below are the VBA and VB.NET code lists for this example. You can experiment with the code by retrieving published models from the repository and then comparing the results obtained by the API with results obtained by the Quick Calculation Pad (QCP).

VBA Sub Main MyRepository Repository MyRepository.ConnectToRepository MyRepository.Project.SetCurrentProject(1) AModel cModel AModel = MyRepository.Model.GetModel(21) Result1 Double Result2 Double Result1 = AModel.Reliability(100) Result2 = AModel.MeanTime ErrorMsg String AModel.SetConfidenceLevel(0.9, ConfBoundsSides_TwoSidedBoth, False, ErrorMsg) BResult1 BoundsValues BResult2 BoundsValues BResult1 = AModel.Bounds_Reliability(100) BResult2 = AModel.Bounds_MeanTime MsgBox ( & Result1 & vbNewLine & _           & BResult1.upper & vbNewLine & _            & BResult1.lower & vbNewLine) MsgBox ( & Result2 & vbNewLine & _           & BResult2.upper & vbNewLine & _            & BResult2.lower & vbNewLine) End Sub

VB.NET Sub Main MyRepository Repository MyRepository.ConnectToRepository MyRepository.Project.SetCurrentProject(1) AModel cModel AModel = MyRepository.Model.GetModel(21) Result1 Double Result2 Double Result1 = AModel.Reliability(100) Result2 = AModel.MeanTime ErrorMsg String AModel.SetConfidenceLevel(0.9, ConfBoundsSides.TwoSidedBoth, False, ErrorMsg) BResult1 BoundsValues BResult2 BoundsValues BResult1 = AModel.Bounds_Reliability(100) BResult2 = AModel.Bounds_MeanTime MsgBox ( & Result1 & vbNewLine & _           & BResult1.upper & vbNewLine & _            & BResult1.lower & vbNewLine) MsgBox ( & Result2 & vbNewLine & _           & BResult2.upper & vbNewLine & _            & BResult2.lower & vbNewLine) End Sub