Skip to main content
Kofax

Parse one OCR result into multiple fields

3801

QAID # 3801 Published

Question / Problem:

How can I use, or where can I find a Validation Script to parse one OCR result into multiple fields?

Answer / Solution:

Below is an example of a Validation Script that parses one OCR field result into multiple Index Fields. This code needs to be placed in the script's KfxDocPreProcess function after the On Error GoTo statement.

Four variables have been created, whose names will have to be changed to match your own field names.

They are:

  • EnteredValue — This value holds the value that was OCR'ed as one zone with all names.
  • Kfx1 — Used for the First Name field.
  • Kfx2 — Used for the Middle Name field, if one existed.
  • Kfx3 — Used for the Last Name field.

Below are the assumptions the code makes:

  • If there are no spaces, place the whole value in the first name field, (Kfx1).
  • If there is 1 space, then there are 2 names place the value before the space in the first name field (Kfx1) and place the value after the space in the last name Field, (Kfx3).
  • If there are 2 spaces, then there are 3 names. Place each name in their respective fields: first (Kfx1), middle (Kfx2) and last name Field, (Kfx3).
  • If there are more that 3 spaces, there are more than 3 names. Set the document to error.

Remember to replace these variables with your field names, remembering that the Validation Script prepends Kfx to each field name.

****************************************************************************
    Dim    strTemp    As    String
    Dim    nStartPos    As    Integer
    Dim    nSpcPos    As    Integer
    Dim    nSpcCnt    As    Integer
    Dim    x    As    Integer
    Dim    nStrLen    As    Integer
EnteredValue = Trim(EnteredValue)
If ( Len(EnteredValue) > MaxLength ) Then GoTo Failure
nSpcPos = 1
nStrLen = Len(EnteredValue)
nSpcPos = InStr(nSpcPos, EnteredValue, Chr(32))
Do While nSpcPos <> 0
    If nSpcPos <= nStrLen Then
        nSpcCnt = nSpcCnt + 1
    End If
    nSpcPos = InStr(nSpcPos +1, EnteredValue, Chr(32))
Loop

If nSpcCnt > 2 Then GoTo Failure

Select Case nSpcCnt
    Case 0
        Kfx1 = EnteredValue
    Case 1
        nSpcPos = 1
        nStartPos = 1
        nSpcPos = InStr(nStartPos, EnteredValue, Chr(32))
        strTemp = Mid(EnteredValue, nStartPos, nSpcPos-1)
        Kfx1 = strTemp
        nStartPos = nSpcPos + 1
        strTemp = Mid(EnteredValue, nStartPos, nStrLen - nSpcPos)
        Kfx3 = strTemp
    Case 2
        nSpcPos = 1
        nStartPos = 1
        nSpcPos = InStr(nStartPos, EnteredValue, Chr(32))
        For x = 1 to 2
            strTemp = Mid(EnteredValue, nStartPos, nSpcPos - nStartPos)
            If x = 1 Then
                Kfx1 = strTemp
            ElseIf x = 2 Then
                Kfx2 = strTemp
            End If
            nStartPos = nSpcPos + 1
            nSpcPos = InStr(nStartPos, EnteredValue, Chr(32))
        Next x
        strTemp = Mid(EnteredValue, nStartPos, nSpcPos - nStartPos)
        Kfx3 = strTemp
End Select

Applies to:

Product Version
CAPTURE 10.0
  10.1
  10.2
  11.0