Survey Tabulation > Advanced expressions > UNICOM Intelligence function library > Miscellaneous functions > Eval
 
Eval
Evaluates an expression and returns the result.
Syntax
Eval(Expr)
Parameters
Expr
Type: Text
Expression to evaluate.
(return)
Type: None
The result of evaluating the expression.
Remarks
The input and output locales and the variables in use in the calling program are passed to this function and used to parse and evaluate the expression. When used in an SQL statement, the values of variables that aren't available in the calling program are taken to be NULL. However, this does not apply when you use the function in mrScriptBasic.
The state of the calling program is shared with the new expression, so that any calls to other functions such as Rot and Ran have the same effect as they would if they were called directly by the calling program.
The type of the return value depends on the type of the expression. If Expr is empty, the return value is NULL. In a scripting environment, the return value is the value of the first statement in the script.
How you specify a text string as an argument depends on whether you are using the function in an SQL query or in mrScriptBasic or mrScriptMetadata. In an SQL query, enclose text strings in single quotation marks ' '. In UNICOM Intelligence Survey Tabulation, mrScriptBasic, and mrScriptMetadata, enclose text strings in double quotation marks " ".
This function is similar to the Eval function in VBScript.
Examples
In mrScriptBasic, you can build up a text string and pass it to the Eval function as if the string were an actual expression. For example, in the following mrScriptBasic code, Eval returns 3:
Dim Total
Total = Eval("1 + 2")
If the text string passed to Eval contains the name of a function, Eval returns the return value of the function. For example, in the following code, Eval returns the current date and time returned by the Now function:
Dim Time
Time = Eval("Now()")
The following example returns 97, which is the value returned by AscW for the "a" character:
Dim MyCheck
MyCheck = Eval("AscW(""a"")")
If the text string passed to Eval in a scripting environment contains more than one statement, Eval executes the statements from left to right but returns the result of the first statement only. For example, the following code includes the mr.CrLf mrScriptBasic constant, which inserts a carriage return/line feed character into a text string. When the code is executed, Eval tests whether the initial values of x and y have the same value and returns True or False accordingly, and then sets the value of x to 5.
Dim Test
Test = Eval("x = y" + mr.CrLf + "x = 5")
This result is different from executing the code outside of the Eval function in mrScriptBasic, where first x would be set to the value of y and then x would be set to 5:
x = y
x = 5
This is because when x = y is the first statement passed to Eval, it is interpreted as an expression that tests whether x and y have the same value, whereas x = y is generally interpreted in mrScriptBasic as an assignment statement, where the value of y is assigned to x.
Outside of the Eval function, the equivalent code would be:
If x = y Then
End If
x = 5
However, if you passed similar code to the Eval function you would get an error:
Test = Eval("If x = y Then" + mr.CrLf + "End If" + mr.CrLf + "x = 5") ' Gives an error
You should therefore take care to make sure that the string passed to Eval is suitable.
See also
Miscellaneous functions