Public Function GetTest(ByVal TestName As String, _ ByVal SubjectPath As String, _ Optional delimChar As String = "\") _ As TDAPIOLELib.Test ' Get a test object with name and path 'This function gets a test name and path and 'returns a test object. Dim TestFact As TestFactory, testList As List Dim testFilter As TDFilter On Error GoTo GetTestErr '-------------------------------------- ' Check arguments. If (Len(SubjectPath) = 0) _ Or (Len(TestName) = 0) Then Set GetTest = Nothing Exit Function End If '-------------------------------------- ' Trim the SubjectPath, stripping leading and trailing delimiters. SubjectPath = Trim(SubjectPath) Dim pos%, ln% pos = InStr(1, SubjectPath, delimChar) If pos = 1 Then SubjectPath = Mid(SubjectPath, 2) End If ln = Len(SubjectPath) pos = InStr(ln - 1, SubjectPath, delimChar) If pos > 0 Then SubjectPath = Mid(SubjectPath, 1, ln - 1) End If '-------------------------------------- ' Path must start with "Subject." pos = InStr(SubjectPath, "Subject") If pos <> 1 Then SubjectPath = "Subject\" & SubjectPath End If '-------------------------------------- ' Get a TestFactory.Filter and define it. 'tdc is the global TDConnection object. Set TestFact = tdc.TestFactory Set testFilter = TestFact.Filter ' The test name testFilter.Filter("TS_NAME") = Trim(TestName) ' The test subject node testFilter.Filter("TS_SUBJECT") = SubjectPath ' Debug.Print TestFilter.Text '-------------------------------------- ' Get the test object. ' The filter defines a unique test, so we ' expect only one test in the list. Set TestFact = tdc.TestFactory Set testList = TestFact.NewList(testFilter.Text) If testList.Count = 0 Then Set GetTest = Nothing Else Set GetTest = testList.Item(1) End If Exit Function GetTestErr: On Error Resume Next Set GetTest = Nothing ErrHandler err, "GetTest", "Failed to get " & TestName End Function