Calculate Results from a Model/VBA
Jump to navigation
Jump to search
Tutorial: Calculate Results from a Model
Below is the VBA version of the tutorial.
VBA Sub Main() 'Connect to a Synthesis repository and project. Dim MyRepository As New Repository MyRepository.ConnectToRepository("C:\RSRepository1.rsr10") 'Replace with name and path to test repository. MyRepository.Project.SetCurrentProject(1) 'Replace with the object ID of test project. 'Retrieve a model from the repository. Dim AModel As cModel Set AModel = MyRepository.Model.GetModel(21) 'Replace with the object ID of test model. 'Declare some variables to store the results. Dim Result1 As Double Dim Result2 As Double 'Calculate the model's reliability at time = 100 hrs and mean time. Result1 = AModel.Reliability(100) Result2 = AModel.MeanTime 'Set the confidence level to 90% two-sided bounds. 'Declare a string variable for any errors found during this method. Dim ErrorMsg As String Call AModel.SetConfidenceLevel(0.9, ConfBoundsSides_TwoSidedBoth, False, ErrorMsg) 'Declare new BoundsValues objects to store the confidence bounds results. Dim BResult1 As BoundsValues Dim BResult2 As BoundsValues 'Calculate bounds for the reliability at 100 hrs and the mean time. Set BResult1 = AModel.Bounds_Reliability(100) Set BResult2 = AModel.Bounds_MeanTime 'Display the output. MsgBox ("Reliability = " & Result1 & vbNewLine & _ "Upper Bound = " & BResult1.upper & vbNewLine & _ "Lower Bound = " & BResult1.lower & vbNewLine) MsgBox ("Mean Time = " & Result2 & vbNewLine & _ "Upper Bound = " & BResult2.upper & vbNewLine & _ "Lower Bound = " & BResult2.lower & vbNewLine) End Sub