6.5

© 2007 ABBYY. All rights reserved.
58
Note: It is recommended to use this method for converting the field text to the number instead of the standard VB Script methods
CCur, CInt, CDb, as the standard methods use the system number format, which can vary on different computers.
Global objects
The users have access to the Form global object. This object belongs to the FormDocument type and represents the document of
the current form.
Support for custom verification rules and error messages
ABBYY FormReader Enterprise Edition provides access to a special function of the FormDocument type that is intended for providing
detailed error messages for custom verifications created using the VBScript language:
Sub SetError( ByVal ErrorMessage, ByVal Optional ErrorFields, Optional ByVal Level )
When ABBYY FormReader Enterprise Edition executes this function, the appropriate error will be added to the error level list of
the document (no dialog box is displayed).
The Level parameter allows the user to set the error level (see Enum TErrorLevel)
The error codes are not supported.
The ErrorFileds parameter is of the Variant (vbArray) type. It contains the array references to the Field objects. To form
errorFileds, use the Array function (predefined VB Script function).
For example:
Sub CheckSumOfNumbers
Dim sum, fields, fld1, fld2, fld3
Set fields = Form.GetPagesForTemplate( "Page 1" ).Item(1).Fields
Set fld1 = fields.ItemByName( "Number1" )
Set fld2 = fields.ItemByName( "Number2" )
Set fld3 = fields.ItemByName( "Number3" )
sum = 0
sum = sum + fld1.ToDecimal
sum = sum + fld2.ToDecimal
sum = sum + fld3.ToDecimal
If sum < 10000 Then
form.SetError "The total amount is less than 10,000.00", Array( fld1, fld2, fld3 ), EL_Error
End If
End Sub
Sequence of calculating the form field values
Sequence of calculating the form field values is specified by the user while the script is executed.
The entry point is Sub Main().
Peculiarities of the script
MsgBox function
The MsgBox function should not be used. This ensures the operation of the script on the server in the unattended mode. Error and
warning messages are displayed to the user by using the SetError function.
Accuracy of the field values
When the VBScript is executed in ABBYY FormReader Enterprise Edition and the Field.SetCheckValue() function assigns the value
to the field, the value is rounded up to the decimal digit specified in the Precision parameter.
The programs use the standard round algorithm corresponding to the VB Script function:
Round(expression[, numdecimalplaces])
The algorithm should be modified explicitly in the expression used for the field value calculation.
Auxiliary function library
The auxiliary function library includes aggregation functions:
ASum
ASumProduct
ACount
ACountNotEmpty
AMin
AMax
AFirst
ALast
The “A” prefix in the function names means “Aggregate”.
Note. The auxiliary function library was written by using the Form Data Access API.
ASum
Function ASum(ByVal pageDefName, ByVal fieldName)