Validates and loads a rules file; a flag determines whether SetVBScriptCalcRules loads after validation or validates without loading.
SetVBScriptCalcRules 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.
Variables cannot be tested for validity, so whenever SetVBScriptCalcRules 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.” |
<HsvSystemInfo>.SetVBScriptCalcRules varabRules, vbScanOnly, pvbErrorsWereFound, pvbWarningsWereFound, pvbInfoWasProvided, pvaralErrorLineNumbers, pvaralErrorSeverity, pvarabstrErrorDescriptions, pvarabstrErrorVBScript, pvarabstrErrorDetails
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 a Variant array of bytes, which is then passed to SetVBScriptCalcRules; note that SetVBScriptCalcRules is set to validate without loading. If the pvbWarningsWereFound argument returns TRUE, the example loops through the pvaralErrorSeverity argument’s 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. vLogText’s value then is written to the log file, which is created with various Visual Basic methods.
Dim cSysInfo As HsvSystemInfo, 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
'm_cHsvSession is an HsvSession object reference
Set cSysInfo = m_cHsvSession.SystemInfo
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
cSysInfo.SetVBScriptCalcRules 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