Copy Code
|
|
---|---|
Private Function FindSimilarBugs() As Boolean ' Search for similar defects 'This routine outputs the number of matches and the 'similarity ratios of the first and last match. 'If you run the example, you'll see that the number of 'matches drops as the similarity ratio goes up. ' Dim BugFact As BugFactory Dim theBug As Bug Dim bugList As List Dim FactList As FactoryList Dim SimRatio As Integer, cnt% Dim DescField As TDField, Description$ Dim FirstLoop As Boolean On Error GoTo FUNC_ERR ' Get the bug factory and output the number of defects. 'tdc is the global TDConnection object. Set BugFact = tdc.BugFactory Set bugList = BugFact.NewList("") cnt = bugList.Count Debug.Print "Total number of defects = " & cnt ' Get a bug object (not important which, for this demo). Set theBug = BugFact.Item(1) ' We'll be looking for Summary and Descriptions similar to these: Debug.Print "The Summary: " & vbCrLf & theBug.Summary '----------------------------------------- 'Use Bug.Field to ' get the Description from the database field. Description = theBug.Field("BG_DESCRIPTION") Debug.Print "The Description: " & vbCrLf & Description & vbCrLf ' Note that at the low ratios it might be hard to see why the defects match. ' At the higher ratios it is clearer. FirstLoop = True For SimRatio = 10 To 100 Step 20 '----------------------------------------- ' Use Bug.FindSimilarBugs. Set FactList = theBug.FindSimilarBugs(SimRatio) Debug.Print "-----------------------------------------" & vbCrLf cnt = FactList.Count Debug.Print "Number of matches found for ratio of " & SimRatio & " = " & cnt If cnt = 0 Then Exit For '----------------------------------------- ' Use FactoryList.Ratio and FactoryList.Item. Debug.Print "------------" Debug.Print "First match ID: " & FactList.Item(1).ID Debug.Print "Ratio of first match = " & FactList.Ratio(1) Debug.Print "Summary:" & vbCrLf & FactList.Item(1).Summary Debug.Print "Description" & vbCrLf & FactList.Item(1).Field("BG_DESCRIPTION") Debug.Print "------------" Debug.Print "Last match ID: " & FactList.Item(cnt).ID 'The last will always be the same item. Output text once. If FirstLoop Then Debug.Print "Ratio of last match = " & FactList.Ratio(cnt) Debug.Print "Summary:" & vbCrLf & FactList.Item(cnt).Summary Debug.Print "Description" & vbCrLf & FactList.Item(cnt).Field("BG_DESCRIPTION") FirstLoop = False End If Next SimRatio FindSimilarBugs = SUCCESS Exit Function FUNC_ERR: FindSimilarBugs = FAILURE End Function |