Here is a QTP quiz for you. We have two functions below. For the first one, argument is passed by reference while for the second, argument is passed by value.

A. Argument is passed by Reference

Function learnqtp( ByRef var)

myname= "jain"
msgbox var
msgbox myname

End Function

myname= "ankur"

call learnqtp (myname)

B. Argument is passed by Value:

Function learnqtp( ByVal var)

myname= "jain"
msgbox var
msgbox myname

End Function

myname= "ankur"

call learnqtp (myname)

Without copying the functions in your QTP editor, try to find:

  1. Output of A.
  2. Output of B.

Why do you think output differ/doesn’t differ? Give your answers in comment below. Now, open QTP and check your answers. Any more comments? 🙂