Sunday, October 17, 2010

VBScript Eval & Execute

VBScript Eval & Execute

EvalExecute
Evaluates an expression and returns the result.


Eval(expression)


expression: String containing any legal VBScript expression.

More on Evaluate
Executes one or more specified statements.


Execute (statement)


statement: The required statement argument is a string expression containing one or more statements for execution. Include multiple statements in the statement argument, using colons or embedded line breaks to separate them.

More on Execute
a="cat"
b="dog"
var=Eval("a=b")
Msgbox var


Returns: False
a="cat"
b="cat"
var=Eval("a=b")
Msgbox var


Returns: True
a="cat"
b="dog"


Execute("a=b")
Msgbox a


Returns: dog
a="cat"


b="dog"
c="apple"
d="orange"
Execute("a=b:c=d")
Msgbox a
Msgbox c


'Returns dog for a
'Returns orange for c
Eval not only evaluates variables but objects, keywords and much more.

An example of Execute

Another example




First it returns - x is EMPTY
Secondly it returns - x is Not EMPTY
Another way to use Execute

Another example

Another example of execute



Above both Call and Execute are doing the same thing.
Another use of Execute

Make sure you have IE open and you are on Google.com


This above statement will put the text QTP in the Google search box.