Create business process test

Private Sub CreateBPTest(oTest As Test, _
    oComponent As Component)
 
' Create a complete Business Process Test
 
' This example creates a complete Business Process Test,
' with BPComponents, groups, iterations and values.
' For demonstration purposes, we create three BPComponents by
' adding the same Component three times. In production code, of
' course, you may add different Components.
    Dim myBPTest As BusinessProcess
    Dim myBPComponent1 As BPComponent
    Dim myBPComponent2 As BPComponent
    Dim myBPComponent3 As BPComponent
    Dim myBPGroup As BPGroup
    Dim myTempIteration As BPIteration
    Dim myTempIterationParam As BPIterationParam
        
'Cast the input test to a BPTest and add the component three times.
'  VisualBasic calls QueryInterface transparently to make this cast.
'  Each addition creates another BPComponent object.
        
    Set myBPTest = oTest
    Set myBPComponent1 = myBPTest.AddBPComponent(oComponent)
    myBPComponent1.order = 2
    myBPComponent1.FailureCondition = "Continue"
    
    ' Adding a component to a Business Process Test automatically
    '   adds an iteration and a BPIterationParam for each ComponentParam.
    '   The parameters will be handled explicitly later in this routine,
    '   so at this point, delete the parameters that were
    '   added automatically.
    myBPComponent1.iterations.Item(1).DeleteIterationParams
    myBPComponent1.iterations.Item(1).order = 0
        
    Set myBPComponent2 = myBPTest.AddBPComponent(oComponent)
    myBPComponent2.order = 1
    myBPComponent2.FailureCondition = "Exit"
    myBPComponent2.iterations.Item(1).DeleteIterationParams
    myBPComponent2.iterations.Item(1).order = 0
        
    Set myBPComponent3 = myBPTest.AddBPComponent(oComponent)
    myBPComponent3.order = 3
    myBPComponent3.FailureCondition = "Exit"
    myBPComponent3.iterations.Item(1).DeleteIterationParams
    myBPComponent3.iterations.Item(1).order = 0
        
'Add the second and third BPComponents to a group.
    Set myBPGroup = myBPTest.AddGroup
    myBPGroup.AddBPComponent myBPComponent3
    myBPGroup.AddBPComponent myBPComponent1
    
'Add iterations
'   Add the same number of iterations to
'   BPComponents of the same group, and add the Order values.
    Set myTempIteration = myBPComponent1.AddIteration
    myTempIteration.order = 1
    Set myTempIteration = myBPComponent1.AddIteration
    myTempIteration.order = 2
    
    Set myTempIteration = myBPComponent2.AddIteration
    myTempIteration.order = 1
    Set myTempIteration = myBPComponent2.AddIteration
    myTempIteration.order = 2
    
    Set myTempIteration = myBPComponent3.AddIteration
    myTempIteration.order = 1
    Set myTempIteration = myBPComponent3.AddIteration
    myTempIteration.order = 2
    
' Add a run time parameter to the test
    Dim myRTParam As RTParam
    Set myRTParam = myBPTest.AddRTParam
    myRTParam.name = "RunTimeParam"
    myRTParam.ValueType = "String"
    
'Handle group.
'For each component in the group, for each iteration in the component:
    ' Set the value of the input parameters to the parameter's name
    ' concatenated to the component's index + iteration's index + parameter's index.
    
    Dim myTempBPParam As BPParameter
    Dim myTempBPComponent As BPComponent
    
    Dim compIdx, iterIdx, paramIdx As Integer
    compIdx = 1: iterIdx = 1: paramIdx = 1
    
    For Each myTempBPComponent In myBPGroup.BPComponents
        For Each myTempIteration In myTempBPComponent.iterations
            For Each myTempBPParam In myTempBPComponent.BPParams
                Set myTempIterationParam = myTempIteration.AddParam(myTempBPParam)
                ' If input
                
                If myTempBPParam.ComponentParamIsOut = 0 Then
                    ' To make this a reference to a run-time parameter,
                    ' set the value to the name of the source run-time parameter
                    ' enclosed in curly brackets.
                    If compIdx = 2 And iterIdx = 1 And paramIdx = 1 Then
                        myTempIterationParam.value = "{" & myRTParam.name & "}"
                    Else
                        ' If a constant value, set the value without curly brackets.
                        myTempIterationParam.value = _
                            myTempBPParam.ComponentParamName & _
                            "_" & compIdx & _
                            "_" & iterIdx & _
                            "_" & paramIdx
                    End If
                End If
                paramIdx = paramIdx + 1
            Next myTempBPParam
            paramIdx = 1
            iterIdx = iterIdx + 1
        Next myTempIteration
        paramIdx = 1
        iterIdx = 1
        compIdx = compIdx + 1
    Next myTempBPComponent
    
'Handle the BPComponent that is not in the above group.
' Add  parameters to the iterations of myBPComponent2,
'   which is not in the group and therefore not handled
'   in the above loop.
    For Each myTempIteration In myBPComponent2.iterations
        For Each myTempBPParam In myBPComponent2.BPParams
            myTempIteration.AddParam myTempBPParam
        Next myTempBPParam
    Next myTempIteration
        
' Connect an output parameter, myBPComponent2.BPParams.Item(3)to
'   an input parameter myBPComponent1.BPParams.Item(1).
'   This makes the value of the input parameter at runtime
'   equal to the output parameter's value.
'
    ' Before the connection can be created, delete any BPIterationParams
    '   currently associated with the input parameter.
    For Each myTempIteration In myBPComponent1.iterations
        myTempIteration.DeleteParam myTempIteration.IterationParams.Item(1)
    Next myTempIteration
    ' Connect the output paramter to the input parameter.
    ' This connection applies to all iterations.
    myBPComponent1.BPParams.Item(1).Reference = myBPComponent2.BPParams.Item(3)
                
' Save the Business Process Test
    myBPTest.Save

End Sub