EVAL Function
Syntax
Arguments
- ExpressionCharacter
A quoted Xbasic statement.
- eval_contextCharacter
The context in which the expression should be evaluated. This can be a list of tables in a CR-LF delimited list. It can also be the name of an open form (suffixed by ".this"), which would evaluate the expression in the context of the form.
- eval_cursorstateCharacter
Internal Use Only.
Returns
- ResultAny Type
Returns the evaluated result of the Xbasic expression.
Description
Return the result of the expression (parses an expression stored in a string, and evaluates it).
Discussion
EVAL() evaluates Expression and returns the result of that expression. This function is useful when the expression to be evaluated is itself constructed by another expression. Contrast with the evaluate_template() function which executes Xbasic code that is stored in a variable.
? eval("1 + 2") = 3 dim varA as N dim varB as N varA = -7 varB = 10 ? eval("varA + varB") = 3 dim theExpresion as C theExpression = "12 - 11 + 2" ? eval(theExpression) = 3 ? eval("date() ") = {03/16/2017} ? eval("date" + "() ") = {03/16/2017}
eval can also be used to create variables. For example:
dim varname as c varname = "lastname" eval(varname) = "smith" ? lastname = "smith"
The following example uses EVAL() to convert a string representation of a fractional number to a number value.
dim amt as C amt = "7 1/23" ? eval( word(amt,1) )+if(w_count(amt)>1,eval( word(amt,2) ),0) = 7.04347826086957
The following example uses EVAL() to evaluate an expression in the context of the 'customer' table.
? eval("lastname + firstname","customer") = "Graham Michael"
The following example uses EVAL() to evaluate an expression in the context of the 'Customer Information' form.
dim f as p f = form.view("Customer Information") ? eval("lastname.text",f.name() + ".this") = "Graham "
See Also