Calculate Results from a Model

 << Back to API Tutorials

Basics
 * 1) Connect or Disconnect from a Synthesis Repository
 * 2) Add New Synthesis Resources to a Repository
 * 3) Edit Existing Synthesis Resources
 * 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 tutorial, you'll learn how to obtain calculated results from models.

Before you begin, publish a model from the repository and note the model's object ID number (see Using Object IDs). You will use the object ID number to retrieve the model, so you can compare the results returned by the API with the results obtained from the Quick Calculation Pad (QCP).

Calculate Results from a Model
1. Create a new module and begin by connecting to a Synthesis repository and project. The following code assumes that a standard repository called "RSRepository1.rsr10" exists in the C drive.

MyRepository Repository MyRepository.ConnectToRepository MyRepository.Project.SetCurrentProject(1)

2. Retrieve a model from the repository. The following code assumes that the repository contains a model with ID number 21.

VBA Amodel cModel AModel = MyRepository.Model.GetModel(21)

VB.NET 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. 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 complete code lists for this example. To test them, run the application by clicking Start on the Debug menu. Compare the results returned by the API with the results obtained from 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 SynthesisAPI Form1 Button1_Click(sender System.Object, e  System.EventArgs)  Button1.Click 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)