Eval

Compiles and evaluates a twinBASIC expression supplied as a string, returning the result as a Variant.

Syntax: Eval( Expression ) As Variant

Expression
required String. A twinBASIC expression that resolves to a value — for example, "2 + 2", "Sqr(2)", or "UCase(""hello"")".

A fresh TbExpressionService is built for every call, with the standard library binder registered so the standard runtime functions (Sin, Sqr, Len, CStr, and the rest) are visible. The expression is then compiled and evaluated once, and the service is discarded.

For repeated evaluation of the same source, or for expressions that need to see your own application objects, build the service yourself and reuse a compiled ITbExpression — see the ExpressionService module for details.

Example

Debug.Print Eval("2 * (Sqr(2) + 1)")    ' 4.82842712474619
Debug.Print Eval("UCase(""hello"")")     ' "HELLO"

See Also