Calculate Results from a Model/VBA: Difference between revisions

From ReliaWiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
Line 10: Line 10:
  {{APIComment|'Connect to a Synthesis repository and project.}}
  {{APIComment|'Connect to a Synthesis repository and project.}}
   {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
   {{APIPrefix|Dim}} MyRepository {{APIPrefix|As New}} Repository
   MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr10"}}){{APIComment|'Replace with name and path to test repository.}}
   MyRepository.ConnectToRepository({{APIString|"C:\RSRepository1.rsr11"}}){{APIComment|'Replace with name and path to test repository.}}
   MyRepository.Project.SetCurrentProject(1){{APIComment|'Replace with the object ID of test project.}}
   MyRepository.Project.SetCurrentProject(1){{APIComment|'Replace with the object ID of test project.}}
   
   

Latest revision as of 18:23, 3 April 2017

APIWiki.png



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.rsr11") '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