Sunday, 22 May 2011

Execute() and Eval() statements in QTP

Evaluates an expression and returns the result.

Eval always take the "=" as comparision
while the execute take the "=" as assignment

In VBScript, x = y can be interpreted two ways. The first is as an assignment statement, where the value of y is assigned to x. The second interpretation is as an expression that tests if x and y have the same value. If they do, result is True; if they are not, result is False. The Execute statement always uses the first interpretation, whereas the Eval method always uses the second.

call evalexecute()
Sub evalexecute
   Dim z
   z = "4"
   print eval("z=5")   & "---  Eval Print  - should return False "
   print eval("z=4")   & "---  Eval Print  - should return True "
   print z    & "---  Eval Print  - value of z should be unchanged"
   print execute ("z=8")   & "- should be blank as execute will not return anything"
   print z     & "---  Eexcute Print - should print 8" 
End Sub

1 comment:

Anonymous said...

Good explanation with an example

Post a Comment

Which one is right ?