SetVBScriptRules

Loads or scans a rules file.

Note:

To validate rules for intercompany transactions, load the rules with SetVBScriptRules2.

SetVBScriptRules returns arrays that contain the line numbers, severity levels, descriptions, contents, and details of the lines in a rules file that do not pass validation. These arrays have a one-to-one correspondence, with one item for each line that does not pass validation.

Tip:

Variables cannot be tested for validity, so whenever SetVBScriptRules encounters a line containing a variable, items with a severity level of Information are included in the arrays. The descriptions for these lines say that “validation was not performed.”

Syntax

<HsvCalculate>.SetVBScriptRules varabRules, vbScanOnly, pvbErrorsWereFound, pvbWarningsWereFound, pvbInfoWasProvided, pvaralErrorLineNumbers, pvaralErrorSeverity, pvarabstrErrorDescriptions, pvarabstrErrorVBScript, pvarabstrErrorDetails

Argument

Description

varabRules

Variant (ByVal). The rules file, passed as an array of bytes.

vbScanOnly

Boolean (ByVal). A flag that specifies whether to load or scan the rules file. Pass TRUE to scan, FALSE to load.

Note:

If you pass FALSE, the rules file is scanned before loading.

pvbErrorsWereFound

Boolean. Indicates whether SetVBScriptRules found any validation errors. Returns TRUE if errors were found, FALSE otherwise.

pvbWarningsWereFound

Boolean. Indicates whether SetVBScriptRules found any validation warnings. Returns TRUE if warnings were found, FALSE otherwise.

pvbInfoWasProvided

Boolean. Indicates whether SetVBScriptRules returns any information not classified as errors or warnings. Returns TRUE if non-error and non-warning information is returned, FALSE otherwise.

pvaralErrorLineNumbers

Variant array. Returns the line numbers to which the errors, warnings, and information apply. The array is returned as a Long subtype.

pvaralErrorSeverity

Variant array. Returns numbers that indicate the severity levels of the errors, warnings, and information. Valid return values are described in the following list:

  • 1 = Error severity level.

  • 2 = Warning severity level.

  • 3 = Information severity level.

The array is returned as a Long subtype.

pvarabstrErrorDescriptions

Variant array. Returns descriptions of the errors, warnings, and information. The array is returned as a String subtype.

pvarabstrErrorVBScript

Variant array. Returns the rules file statements to which the errors, warnings, and information apply. The array is returned as a String subtype.

pvarabstrErrorDetails

Variant array. Returns details that describe why the lines caused validation to fail. The array is returned as a String subtype.

Example

The following example creates a log file that lists the line numbers, descriptions, and details for any validation messages of a warning severity level. Various Visual Basic methods convert the rules file to an array of bytes, which is then passed to SetVBScriptRules; note that SetVBScriptRules is set to scan. If the pvbWarningsWereFound argument returns TRUE, the example loops through the pvaralErrorSeverity argument array to find items flagged with a warning severity level. For each such item, the corresponding items returned in the pvaralErrorLineNumbers, pvarabstrErrorDescriptions, and pvarabstrErrorDetails arguments are concatenated to the vLogText variable. When the loop finishes, vLogText’s value is written to the log file, which is created by using various Visual Basic methods.

Dim cCalculate As HsvCalculate, vFileName, lFile As Long
Dim lSize As Long, vaRules, bytaRules() As Byte
Dim bErrs As Boolean, bWarnings As Boolean, bInfo As Boolean
Dim valLines, valSeverity, vasDescs, vasErr, vasDetails
Dim vLogText, iFile As Integer
Set cCalculate = m_cHsvSession.Calculate
vFileName = "C:\Program Files\Acme\AppRules.rle"
lFile = FreeFile
lSize = FileLen(vFileName)
Open vFileName For Binary Access Read As #lFile
ReDim bytaRules(lSize)
Get #lFile, , bytaRules
Close #lFile
vaRules = bytaRules
cCalculate.SetVBScriptRules vaRules, True, bErrs, bWarnings, _ 
bInfo, valLines, valSeverity, vasDescs, vasErr, vasDetails
If bWarnings = True Then
  For i = LBound(valLines) To UBound(valLines)
    If valSeverity(i) = 2 Then
      vLogText = vLogText & "Line #: " & valLines(i) & _ 
      vbCrLf & "   Description:  " & vasDescs(i) & vbCrLf _ 
      & "   Details:  " & vasDetails(i) & vbCrLf & vbCrLf
    End If
  Next i
iFile = FreeFile
  Open "C:\Program Files\Acme\warnings.log" For Output As #iFile
  Print #iFile, vLogText
  Close #iFile
End If