×
Menu
Index

3.6.2.11. Sum a Capture Grid Column

 
 
This example shows how to loop capture grid records and extract the data from a column to sum the values to compare it to a "Net Total" field
 
 
 
 
The sum of "Line total" in capture grid has to be the same as the "Net Total" Field.
 
There is an event "OnXGridValueChanged". This even occurs when capture grid is read or any value is manually changed.
 
This is the code for it:
 
SetLocale("en-us")
 
Dim numRows
Dim GridPanel
 
GridPanel=1'first panel
numRows=ChronoDocument.GetXgridRowCount (GridPanel)
 
Dim Total
Total=0
Dim row
For row = 0 To numRows-1
Dim lineTotal
    lineTotal=ChronoDocument.GetXgridFieldValue (GridPanel, row, "Line total")
    Total=Total + CDbl(lineTotal)
Next
 
 
' Validate values
dif = Abs(CDbl(UserField_Net_Total.value) - Total)
If dif <= 0.03 Then
    UserField_Net_Total.ValidateStatus = true
Else
    UserField_Net_Total.ValidateStatus = false
    UserField_Net_Total.ValidateMessage = "Net Total is not equal to Sum all lines " & Total
End If
 
UserField_Net_Total.Validate