Work with line item tables, bank account tables, and tax tables

Retrieving info from tables

This tutorial demonstrates how to manipulate tables, such as line item tables, bank account tables, and tax tables. In this tutorial you will:

  • Retrieve table information.
  • Set table values.
  • Delete tables.
  • Delete rows from a table.

See the Hello World tutorial for details about creating a DLL and connecting it to Kofax ReadSoft Invoices via Eilocal.ini.

The PrintInfo function demonstrates how to retrieve values from tables. Note that you use the properties- LineItemRows, BankAccountRows, and VATRows- to specify the page on which the table occurs, not the row you want to retrieve.

The following excerpt calls the PrintInfo function, which returns values from the specified LineItemRow object.

 PrintInfo "LineItemRows",
obInvoice.LineItemRows(1)

The PrintInfo function uses the LineItemRow object to display the number of rows and columns, if any.

Private Function PrintInfo(sType As String, obRows As LineItemRows)

    

    If obRows Is Nothing Then Exit Function

    ' Print the table type and number of rows in the Immediate window.

    Debug.Print sType & " - Number of rows: " & obRows.Count

    

    If obRows.Count > 0 Then

        ' Print the table type and number of columns,

        ' if any, in the Immediate window.

        Debug.Print sType & " - Number of columns: " & obRows(1).Fields.Count

    Else

        Debug.Print sType & " - No columns (or no rows)"

    End If

    

End Function

The FillWithValues function demonstrates how to:

  • Add rows and values to a table.
  • Set the status of a field.

Private Sub FillWithValues(obRows As LineItemRows)

   If obRows Is Nothing Then Exit Sub

   

   Dim obRow As LineItemRow

   Dim obField As EHICOM.InvoiceField

   Dim f As Long

   

   Dim i As Long

   For i = 1 To obRows.Count

      Set obRow = obRows.Item(i)

      ' Iterate through all the fields and add values.

      For f = 1 To obRow.Fields.Count

         Set obField = obRow.Fields.Item(f)

         obField.Value = i & " -> " & f

         ' Set the field status to complete.

         obField.Status = eiFieldComplete

      Next f

   Next i

   Set obRow = obRows.Add

   ' Add new rows.

   For f = 1 To obRow.Fields.Count

      Set obField = obRow.Fields.Item(f)

      obField.Value = "Nytt: " & f

      obField.Status = eiFieldComplete

   Next f

End Sub

The following functions demonstrate how to delete table rows.

Private Sub DeleteAllRows(obRows As LineItemRows)

   If obRows Is Nothing Then Exit Sub

   ' Delete all rows.

   obRows.DeleteAll

End Sub

Private Sub DeleteFirstRow(obRows As LineItemRows)

   If obRows Is Nothing Then Exit Sub

   ' Delete the first row.

   obRows.Item(1).Delete

End Sub

The OnInvoiceVerify function calls all of the example functions.

Public Function OnInvoiceVerify() As Long

   ' Declare a reference to the Invoice object.

   Dim obInvoice As EHICOM.Invoice

   ' Set the Invoice object to the current invoice.

   Set obInvoice = objEHApplication.CurrentInvoice

 

   ' Display the table data in Visual Studio's Immediate window.

   PrintInfo "LineItemRows", obInvoice.LineItemRows(1)

   PrintInfo "BankAccountRows", obInvoice.BankAccountRows(1)

   PrintInfo "VATTableRows", obInvoice.VATRows(1)

 

   ' Delete the first row from each table.

   DeleteFirstRow obInvoice.LineItemRows(1)

   DeleteFirstRow obInvoice.BankAccountRows(1)

   DeleteFirstRow obInvoice.VATRows(1)

 

   ' Display the table data in Visual Studio's Immediate window.     

   PrintInfo "LineItemRows", obInvoice.LineItemRows(1)

   PrintInfo "BankAccountRows", obInvoice.BankAccountRows(1)

   PrintInfo "VATTableRows", obInvoice.VATRows(1)

      

   ' Insert values in each table.

   FillWithValues obInvoice.LineItemRows(1)

   FillWithValues obInvoice.BankAccountRows(1)

   FillWithValues obInvoice.VATRows(1)

   

   ' Prompt to delete all the rows.

   If MsgBox("Delete all rows?", vbYesNo, "Example Project") = vbYes Then

      DeleteAllRows obInvoice.LineItemRows(1)

      DeleteAllRows obInvoice.BankAccountRows(1)

      DeleteAllRows obInvoice.VATRows(1)

   End If

   ' Return

   OnInvoiceVerify = 0

End Function

The complete code should look like this

Option Explicit

Option Compare Text

' Declare a reference to the Application object.

Private objEHApplication As EHICOM.VerifyApp

 

Public Function Connect(objEHIApp As Object, sIniFile As String, sIniSection As String) As Long

    ' Set the application object for future reference.

    Set objEHApplication = objEHIApp

    ' Inject the OnInvoiceVerify function.   

    objEHApplication.Subscribe Me, "InvoiceVerify", "OnInvoiceVerify"

    ' Return evtOK.

    Connect = evtOK

End Function

 

Public Function OnInvoiceVerify() As Long

   ' Declare a reference to the Invoice object.

   Dim obInvoice As EHICOM.Invoice

   ' Set the Invoice object to the current invoice.

   Set obInvoice = objEHApplication.CurrentInvoice

 

   ' Display the table data in Visual Studio's Immediate window.

   PrintInfo "LineItemRows", obInvoice.LineItemRows(1)

   PrintInfo "BankAccountRows", obInvoice.BankAccountRows(1)

   PrintInfo "VATTableRows", obInvoice.VATRows(1)

 

   ' Delete the first row from each table.

   DeleteFirstRow obInvoice.LineItemRows(1)

   DeleteFirstRow obInvoice.BankAccountRows(1)

   DeleteFirstRow obInvoice.VATRows(1)

 

   ' Display the table data in Visual Studio's Immediate window.     

   PrintInfo "LineItemRows", obInvoice.LineItemRows(1)

   PrintInfo "BankAccountRows", obInvoice.BankAccountRows(1)

   PrintInfo "VATTableRows", obInvoice.VATRows(1)

      

   ' Insert values in each table.

   FillWithValues obInvoice.LineItemRows(1)

   FillWithValues obInvoice.BankAccountRows(1)

   FillWithValues obInvoice.VATRows(1)

   

   ' Prompt to delete all the rows.

   If MsgBox("Delete all rows?", vbYesNo, "Example Project") = vbYes Then

      DeleteAllRows obInvoice.LineItemRows(1)

      DeleteAllRows obInvoice.BankAccountRows(1)

      DeleteAllRows obInvoice.VATRows(1)

   End If

   ' Return

   OnInvoiceVerify = 0

End Function

 

Private Sub DeleteAllRows(obRows As LineItemRows)

   If obRows Is Nothing Then Exit Sub

   ' Delete all rows.

   obRows.DeleteAll

End Sub

Private Sub FillWithValues(obRows As LineItemRows)

   If obRows Is Nothing Then Exit Sub

   

   Dim obRow As LineItemRow

   Dim obField As EHICOM.InvoiceField

   Dim f As Long

   

   Dim i As Long

   For i = 1 To obRows.Count

      Set obRow = obRows.Item(i)

      ' Iterate through all the fields and add values.

      For f = 1 To obRow.Fields.Count

         Set obField = obRow.Fields.Item(f)

         obField.Value = i & " -> " & f

         ' Set the field status to complete.

         obField.Status = eiFieldComplete

      Next f

   Next i

   Set obRow = obRows.Add

   ' Add new rows.

   For f = 1 To obRow.Fields.Count

      Set obField = obRow.Fields.Item(f)

      obField.Value = "Nytt: " & f

      obField.Status = eiFieldComplete

   Next f

End Sub

 

Private Function PrintInfo(sType As String, obRows As LineItemRows)

    

    If obRows Is Nothing Then Exit Function

    ' Print the table type and number of rows in the Immediate window.

    Debug.Print sType & " - Number of rows: " & obRows.Count

    

    If obRows.Count > 0 Then

        ' Print the table type and number of columns,

        ' if any, in the Immediate window.

        Debug.Print sType & " - Number of columns: " & obRows(1).Fields.Count

    Else

        Debug.Print sType & " - No columns (or no rows)"

    End If

    

End Function

Private Sub DeleteFirstRow(obRows As LineItemRows)

   If obRows Is Nothing Then Exit Sub

   ' Delete the first row.

   obRows.Item(1).Delete

End Sub

Related topics

Hello World tutorial

LineItemRows collection