Difference between Eval & Execute
In the syntax above, bothexpression
and statement
arguments are string statements. Both expressions can be derived from VBScript or QTP code; the difference lies in the fact that Eval will always return the result of the string evaluation whereas Execute will execute a string statement for execution and will not retrieve the result (but there are workarounds). The following example demonstrates the main difference between the 2 functions:x = 9 y = 10 bIsEqual = Eval("x = y") Execute "x = y" MsgBox "bIsEqual: " & bIsEqual MsgBox "X is no longer 9. It is: " & x |
Eval Function
|
Execute Statement
|
You must be wondering why the syntax for Eval and Execute is different. The reason is that, Eval is a function. Execute is not. That means, the following statement for Eval:
bIsEqual = Eval("x = y")
, when written for Execute will return a Null value for bResult (but assignment will be performed for x
):bResult = Execute("x = y") MsgBox bResult MsgBox "x: " & x |
Null Output
|
X = 10
|
Eval
. Here’s how:x = 9 y = 10 Execute "z = (x = y)" MsgBox "z: " & z ' how come its evaluating the |
Return Z (False)
No comments:
Post a Comment