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

  1. Function learnqtp( ByRef var)
  2.  
  3. myname= "jain"
  4. msgbox var
  5. msgbox myname
  6.  
  7. End Function
  8.  
  9. myname= "ankur"
  10.  
  11. call learnqtp (myname)

B. Argument is passed by Value:

  1. Function learnqtp( ByVal var)
  2.  
  3. myname= "jain"
  4. msgbox var
  5. msgbox myname
  6.  
  7. End Function
  8.  
  9. myname= "ankur"
  10.  
  11. 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? 🙂