Parse
parse
parses a formula contained in a character string and returns an error value if the formula is not syntactically correct.
parse(STRING_EXPR)
STRING_EXPR
is a string expression or a variable that returns the expression to be parsed.# First simple exampleLocal Integer FIELD1IF_OK=parse("1+1") : # FIELD1 contains now 0 (ok)IF_OK=parse("1+") : # FIELD1 contains now 5 (illegal character)# Second example: check first if the formula is syntactically valid, then manage the error# Returns the result of the evaluation in a string# If an error occurs, ERROR_CODE is not null and the result is an empty stringSubprog EVALUE(FORMULA,RESULT,ERROR_CODE)Value Char FORMULA()Variable Char RESULTVariable Integer ERROR_CODE# Is the formula correct?ERROR_CODE=parse(FORMULA)If ERROR_CODE<>0 : RESULT="" : End : Endif# Handle the errorsOnerrgo ERR_EVALUERESULT=num$(evalue(FORMULA))ERROR_CODE=0End# Error handling$ERR_EVALUERESULT=""ERROR_CODE=errnEnd
parse
parses the content of a character string as a formula and returns 0 if the syntax is OK. Otherwise, it returns an error code (usually 5: incorrect character).
If the argument of parse
is a string array, the different lines in the array are concatenated and the result is parsed.
A second argument can be given for parse
, but this syntax is deprecated and must not be used.
Error code | Description. |
---|---|
10 | The argument is not a string. |