FieldChars collection example

The following code illustrates the use of a collection object and some methods and properties of the Field, FieldChars, and FieldChar objects.

Note

If you want to test this method, copy it to a Visual Basic ActiveX DLL or ActiveX EXE project.

Public Sub IncreaseItrpResult()

'----------------------------------------------------------------------

' Call this function in the FieldInterpreted event in the

' Interpret module.

' All * (uninterpretable) characters are replaced by the best guess

' if the guess confidence is greater than 10%.

'----------------------------------------------------------------------

    Dim objCurrField As Object

    Dim objFieldChar As Object

    Dim colFieldChars As Object

    Dim strInterpretResult As String

    Dim intPos As Integer

    Dim intGuess As Integer

    Dim intConfidence As Integer

    Dim intResult As Integer

 

    Set objCurrField = InterpretApp.Field

    Set colFieldChars = objCurrField.FieldChars

    strInterpretResult = objCurrField.Value

 

    If Not InStr(1, strInterpretResult, "*") Then

        'Skip if no uninterpretable characters

            Exit Sub

    End If

 

 

    For Each objFieldChar In colFieldChars

        intPos = InStr(1, strInterpretResult, "*")

        intResult = objFieldChar.GetGuess(1, intGuess, intConfidence)

        If intResult = 0 Then

            If intConfidence > 10 Then

                strInterpretResult = _

                    Left(strInterpretResult, intPos - 1) & _

                    Chr(intGuess) & _

                    Mid(strInterpretResult, intPos + 1)

                    End If

            End If

 

    If (intResult <> 0) Or (intGuess <= 10) Then

        'Convert temporary * back to $

            Call Replace(strInterpretResult, "*", "$")

            End If

 

    Next objFieldChar

 

    'Convert all temporary $ back to *

    Call Replace(strInterpretResult, "$", "*")

 

    'Update field value

    objCurrField.Value = strInterpretResult

 

End Sub