Private Sub ScrRelations_LocateAlternatives(ByVal pXDoc As CASCADELib.CscXDocument, ByVal pLocator As CASCADELib.CscXDocField)
Dim oAlts1 As CscXDocFieldAlternatives
Dim oAlts2 As CscXDocFieldAlternatives
Dim arrAlts() As CscXDocFieldAlternative
Dim oAlt As CscXDocFieldAlternative
Dim oNewAlt As CscXDocFieldAlternative
Dim i As Long
Set oAlts1 = pXDoc.Locators.ItemByName("FmtCrownAgents").Alternatives
Set oAlts2 = pXDoc.Locators.ItemByName("FmtNumbers").Alternatives
arrAlts = EvaluateAlternativesRelationships(oAlts1, oAlts2, 1, 10)
For i = LBound(arrAlts) To UBound(arrAlts)
Set oAlt = arrAlts(i)
If oAlt Is Nothing Then
Exit For
End If
Set oNewAlt = pLocator.Alternatives.Create()
oNewAlt.Confidence = oAlt.Confidence
oNewAlt.Height = oAlt.Height
oNewAlt.Left = oAlt.Left
oNewAlt.Text = oAlt.Text
oNewAlt.Top = oAlt.Top
oNewAlt.Width = oAlt.Width
Next
End Sub
Private Function EvaluateAlternativesRelationships(ByVal alts1 As CscXDocFieldAlternatives, ByVal alts2 As CscXDocFieldAlternatives, _
ByVal minLineDistance As Long, ByVal maxLineDistance As Long) As CscXDocFieldAlternative()
Dim i As Long
Dim j As Long
Dim lAltsIndex As Long
Dim arrAlts() As CscXDocFieldAlternative
Dim oAlt1 As CscXDocFieldAlternative
Dim oAlt2 As CscXDocFieldAlternative
Dim lAlt1Line As Long
Dim lAlt2Line As Long
Dim lLineDistance As Long
ReDim arrAlts(99)
lAltsIndex = -1
For i = 0 To alts1.Count - 1
Set oAlt1 = alts1.ItemByIndex(i)
If oAlt1.Words.Count > 0 Then
lAlt1Line = oAlt1.Words.ItemByIndex(0).LineIndex
For j = 0 To alts2.Count - 1
Set oAlt2 = alts2(j)
If oAlt2.Words.Count > 0 Then
lAlt2Line = oAlt2.Words.ItemByIndex(0).LineIndex
lLineDistance = lAlt2Line - lAlt1Line
If lLineDistance >= minLineDistance And lLineDistance <= maxLineDistance Then
lAltsIndex = lAltsIndex + 1
If lAltsIndex > UBound(arrAlts) Then
ReDim Preserve arrAlts(UBound(arrAlts) + 99)
End If
Set arrAlts(lAltsIndex) = oAlt2
End If
End If
Next
End If
Next
If lAltsIndex > -1 And lAltsIndex < UBound(arrAlts) Then
ReDim Preserve arrAlts(lAltsIndex)
End If
EvaluateAlternativesRelationships = arrAlts
End Function