@CheckFormulaSyntax (Formula Language)

Checks a block of commented out formula language code for errors.

Note: This @function is new with Release 6.

Syntax

@CheckFormulaSyntax(formulaText)

Parameters

formulaText

Text. The formula code to test for errors, commented out. Enclose the formula code in braces ({}) to comment out the code.

Return value

errorInformation

Text or textlist.

  • Returns "1" if the formula has no errors.
  • Returns the text list "errorMessage" : "errorLine" : "errorColumn" : "errorOffset" : "errorLength" : "errorText" where each list item is defined as follows:

    errorMessage: Message returned by the compiler.

    errorLine: Line where the error occurred, beginning with 1, not zero. New lines created by wrapped text are not counted.

    errorColumn: Number of character spaces from the first character in the line where the error occurred, beginning with 1.

    errorOffset: Number of character spaces from the first character in the formulaText block where the error occurred, beginning with 1.

    errorLength: Length of the text making up the error.

    errorText: Text or token that the compiler processes as the cause of the error.

Usage

The formula you are checking is not "commented out". {) are quote characters. The argument to the function is a string which contains the formula to be checked, not a comment. It is no different from any other function that takes a string argument. The reason { } is used in the examples rather than the more usual double quotes, is because the string you are quoting is likely to contain double quotes. Using { } avoids "escaping" the quotes within the text. If the value is not hard coded but read from a field, as it would be in most applications, this is not an issue.

This @function reports compile errors, not run-time errors. A run-time error is generated, for example, if a function has an insufficient number of arguments. This function is useful especially if you are using the @Eval function to execute a text expression at run-time, since you can use it to first check the syntax of any text you supply to @Eval.

Note: Do not use the expression @CheckFormulaSyntax(...) = "1" to test that there is not an error, because this will return True if there is a "1" in any element of the returned error information, for example, if the error is on line 1.

Examples

  1. This example returns "Unknown @Function":"4":"1":"60":"8":"@MailSnd" when used as the default value for a text field.
    formula := {subject:="test";
    remark:="ok";
    SendTo:="Darrin Dogs/Star";
    @MailSnd(SendTo;"";"";subject;remark;"ID";[Sign]:[Encrypt])};
    @CheckFormulaSyntax(formula);
  2. This code returns "1" when used as the default value for a text field.
    formula := {subject:="test";
    remark:="ok";
    SendTo:="Darrin Dogs/Star";
    @MailSend(SendTo;"";"";subject;remark;"ID";[Sign]:[Encrypt])};
    @CheckFormulaSyntax(formula);
  3. This Input Validation formula checks that the user has entered a valid formula in a text field:
    @If(@ThisValue= ""; 
    @Return(@Failure("You must enter a formula here.")); 
    0);
    -tmp[1] :=  @CheckFormulaSyntax(@ThisValue);
    @If(_tmp[1] = "1";
    = "1"; 
    @Success; 
    @Failure("Invalid formula: " + -tmp[1] + " on line " + -tmp[2]))