Promote parameters from a component to a flow

Private Sub PromoteFlowOutputParameters()

' Promote parameters from a component to a flow
' Promote Business Components' output parameters to the flow level.
' This example assumes the connected project contains
' a Business Component with output parameters and
' a Flow that uses the Business Component. The Flow may have
' iterations.

    On Error GoTo handle_errors

    Dim tstFactory As TestFactory
    Dim tst As Test
    Dim fl As IBusinessProcess2
    Dim bpComp As BPComponent
    Dim bpParam As BPParameter
    Dim newFlowOutputParam As ComponentParam
    Dim iter As BPIteration
' Find a test of type "Flow"
    Set tstFactory = tdc.TestFactory
    For Each tst In tstFactory.NewList("")
     If (tst.Type = "FLOW") Then
        Set fl = tst
        Exit For
     End If
    Next tst

    If fl Is Nothing Then
        MsgBox "No flow tests in project"
        Exit Sub
    End If
    Dim VersionCntl As Object
    Dim NoCheckoutError As Boolean
' Check the test out of version control and load the test.
    ' The code of CheckoutTest is the example to the
' Test coclass, "Checking out a Test."
    Set VersionCntl = _
        CheckoutTest(tst, "Promote output params", NoCheckoutError)
    If Not NoCheckoutError Then Exit Sub
' Promote each of the BP output parameters
' in each iteration to the flow level.
    ' Flow's components.
    For Each bpComp In fl.BPComponents
        Debug.Print "BPComp Name = " &
    ' Iterations of components.
        For Each iter In bpComp.iterations
            Debug.Print "Iter ID= " & iter.ID & ", iterOrder = " & iter.order
         ' BP parameters of iteration.
            For Each bpParam In bpComp.BPParams
                Debug.Print bpParam.ComponentParamName & ",  " & bpParam.ID
                ' If output parameter, promote to flow level.
                'If bpParam.ComponentParamIsOut <> 0 Then
                If bpParam.ComponentParamIsOut Then
                    Set newFlowOutputParam = _
                        fl.AddFlowOutputParam( _
                            bpParam, _
                            iter.order + 1, _
                              & "_iteration_" & (iter.order + 1))
                End If
            Next bpParam
        Next iter
    Next bpComp
' Print all of the flow's output parameters.
    For Each newFlowOutputParam In fl.FlowOutputParameters
    Next newFlowOutputParam
'Save and check in.
    On Error Resume Next
    NoCheckoutError = CheckinTest(VersionCntl, "Parameters Promoted")
    If Not NoCheckoutError Then ErrHandler Null, "PromoteFlowOutputParameters", "Checkin Failed", NON_FATAL_ERROR
    Set VersionCntl = Nothing
    Set tstFactory = Nothing
    Set fl = Nothing
    Set bpComp = Nothing
    Set bpParam = Nothing
    Set newFlowOutputParam = Nothing
    Set iter = Nothing
Exit Sub

    ErrHandler err, "PromoteFlowOutputParameters", "", NON_FATAL_ERROR
    Resume Next

End Sub