Sub CheckFormulaSyntax(Byval sFormulaField As String)
' *********************************************************************************
' FUNCTION Header
' *********************************************************************************
' Purpose:
' Check the value in a field for using as formula
'
' Parameter:
' sFormulaField - Fieldname where the formula was written
'
' Return Value:
' -none-
'
' Dependencies:
' -none-
' *********************************************************************************
' ------------------------------------------------------------------------------------------------------------
' Constants
' ------------------------------------------------------------------------------------------------------------
REM MsgBox Icons
Const MB_ICONSTOP = 16 ' Critical message
Const MB_ICONINFORMATION = 64 ' Information message
REM Constance with message texts for communication with user
Const COMPILE_SUCCESS_TITLE = "Compiled Successfully"
Const COMPILE_SUCCESS_BODY = "There are no syntax errors, the formula compiled successfully."
Const COMPILE_FAILURE_TITLE = "Syntax Error"
Const COMPILE_FAILURE_BODY = "There is at least one syntax error in the formula. It did not compile."
Const COMPILE_FAILURE_SAVE_BODY = "There is at least one syntax error in the formula. This document could not be saved."
' END Constants
' ------------------------------------------------------------------------------------------------------------
' Declarations
' ------------------------------------------------------------------------------------------------------------
REM Object vars
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
REM Message box vars
Dim sMB_Prompt As String
Dim nMB_Info As Long
Dim sMB_Title As String
REM additional vars
Dim sFormula As String
Dim vEval As Variant
' END Declarations
' ------------------------------------------------------------------------------------------------------------
' Initialize
' ------------------------------------------------------------------------------------------------------------
REM Objects
Set uidoc = ws.CurrentDocument
Set doc = uidoc.Document
' END Initialize
' *********************************************************************************
' MAIN PROGRAM
' *********************************************************************************
sFormula = | @CheckFormulaSyntax( | & sFormulaField & | ) |
vEval = Evaluate(sFormula, doc)
If vEval(0) = "1" Then
Messagebox COMPILE_SUCCESS_BODY, MB_ICONINFORMATION, COMPILE_SUCCESS_TITLE
Else
Msgbox COMPILE_FAILURE_BODY & Chr(13) & "Error type: " & vEval(0) & Chr(13) & "Error message: " & vEval(5)_
, MB_ICONSTOP, COMPILE_FAILURE_TITLE
End If
End Sub
Hinweis:
Ein eigenstndiges Tool zum Testen ("Formula Validator") findet sich auch in unserem Downloadbereich.....