SlideShare a Scribd company logo
for more QTP scripts, visit                              www.ramupalanki.com

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?

Technorati Tags: hp qtp,qtp quiz,by value,by reference
for more QTP scripts, visit                      www.ramupalanki.com


 I'm sure you have already subscribed to our feed but just in case not. I recommend
 you to subscribe via RSS feed. You can also subscribe by Email and have new QTP
 articles sent directly to your inbox.


Related posts:

   1. Quiz: A message box that will close automatically
   2. Quiz: Find the difference between these VBScript codes?
   3. How to load a DLL with QTP?

7 comments ↓

#1 Percy Bell on 11.03.08 at 7:17 am

       A:
       jain
       jain

       B:
       ankur
       jain

       Passing by Value is just that. It passes a value to the function to use. It creates a
       new space to hold this value.

       Passing by Reference passes the pointer to the memory space for the variable.
       This means that anything you do to the variable in the function changes the actual
       value of the passed variable. This means that if you changed the variable in the
       function it will be changed outside the function too.

#2 Zecty on 11.03.08 at 10:11 am

       The output will be different. The first code (byRef), will output the name “jain”
       twice. Because, when a variable is passed by reference, both the variable “var”
       (passed as a parameter) and “myname” (used inside the function) will point to the
       same memory space. Since “myname” was not declared (“dim”) inside the
       function, when a variable is passed by reference in vbscript, use of the variable
       name refers to the calling scope’s use of the variable. But when passed by value
       (byVal), the “myname” variable used inside the function and the “var” parameter,
       will both be ‘local variables’ that are instantiated only for the life of the function,
       and do not affect the memory area used by the ‘global’ “myname” variable.

       This shows why it is a good reason to always declare variables!
for more QTP scripts, visit   www.ramupalanki.com

More Related Content

What's hot

How we migrated Zalando app to Swift3?
How we migrated Zalando app to Swift3?How we migrated Zalando app to Swift3?
How we migrated Zalando app to Swift3?
Vijaya Prakash Kandel
 
How to specify `frozen_string_literal: true`
How to specify `frozen_string_literal: true`How to specify `frozen_string_literal: true`
How to specify `frozen_string_literal: true`
Kazuhiro Nishiyama
 
Idiomatic Kotlin for Android
Idiomatic Kotlin for AndroidIdiomatic Kotlin for Android
Idiomatic Kotlin for Android
Matthew Clarke
 
Things you wish you never knew about the Prometheus Remote Write API.
Things you wish you never knew about the Prometheus Remote Write API.Things you wish you never knew about the Prometheus Remote Write API.
Things you wish you never knew about the Prometheus Remote Write API.
Kausal
 
Async/Await: TPL & Message Pumps
Async/Await: TPL & Message Pumps Async/Await: TPL & Message Pumps
Async/Await: TPL & Message Pumps
Particular Software
 
C# 5 deep drive into asynchronous programming
C# 5 deep drive into asynchronous programmingC# 5 deep drive into asynchronous programming
C# 5 deep drive into asynchronous programming
Praveen Prajapati
 
Using assm in service object
Using assm in service object Using assm in service object
Using assm in service object
Railwaymen
 
Intro to javascript (6:19)
Intro to javascript (6:19)Intro to javascript (6:19)
Intro to javascript (6:19)
Thinkful
 
Clustering and load balancing : jboss
Clustering and load balancing : jbossClustering and load balancing : jboss
Clustering and load balancing : jboss
Lalit Shaktawat
 
Serverless in production, an experience report (LNUG)
Serverless in production, an experience report (LNUG)Serverless in production, an experience report (LNUG)
Serverless in production, an experience report (LNUG)
Yan Cui
 
Rails 5 – Amsterdam.rb – Uberous
Rails 5 – Amsterdam.rb – UberousRails 5 – Amsterdam.rb – Uberous
Rails 5 – Amsterdam.rb – Uberous
Jeroen Visser
 
Async/Await Best Practices
Async/Await Best PracticesAsync/Await Best Practices
Async/Await Best Practices
Particular Software
 
Serverless in Production, an experience report (cloudXchange)
Serverless in Production, an experience report (cloudXchange)Serverless in Production, an experience report (cloudXchange)
Serverless in Production, an experience report (cloudXchange)
Yan Cui
 
Leveraging Micronaut on AWS Lambda
Leveraging Micronaut on AWS LambdaLeveraging Micronaut on AWS Lambda
Leveraging Micronaut on AWS Lambda
Naresha K
 
Lets build-ruby-app-server: Vineet tyagi
Lets build-ruby-app-server: Vineet tyagiLets build-ruby-app-server: Vineet tyagi
Lets build-ruby-app-server: Vineet tyagi
ThoughtWorks
 
Javascript Workshop
Javascript WorkshopJavascript Workshop
Javascript Workshop
Assaf Weinberg
 
Async Programming in C# 5
Async Programming in C# 5Async Programming in C# 5
Async Programming in C# 5
Pratik Khasnabis
 
Custom Mongrel Handlers: Learning how to walk the dog
Custom Mongrel Handlers: Learning how to walk the dogCustom Mongrel Handlers: Learning how to walk the dog
Custom Mongrel Handlers: Learning how to walk the dog
Ezra Zygmuntowicz
 

What's hot (20)

How we migrated Zalando app to Swift3?
How we migrated Zalando app to Swift3?How we migrated Zalando app to Swift3?
How we migrated Zalando app to Swift3?
 
Callback Function
Callback FunctionCallback Function
Callback Function
 
How to specify `frozen_string_literal: true`
How to specify `frozen_string_literal: true`How to specify `frozen_string_literal: true`
How to specify `frozen_string_literal: true`
 
Idiomatic Kotlin for Android
Idiomatic Kotlin for AndroidIdiomatic Kotlin for Android
Idiomatic Kotlin for Android
 
CAPISTRANO
CAPISTRANOCAPISTRANO
CAPISTRANO
 
Things you wish you never knew about the Prometheus Remote Write API.
Things you wish you never knew about the Prometheus Remote Write API.Things you wish you never knew about the Prometheus Remote Write API.
Things you wish you never knew about the Prometheus Remote Write API.
 
Async/Await: TPL & Message Pumps
Async/Await: TPL & Message Pumps Async/Await: TPL & Message Pumps
Async/Await: TPL & Message Pumps
 
C# 5 deep drive into asynchronous programming
C# 5 deep drive into asynchronous programmingC# 5 deep drive into asynchronous programming
C# 5 deep drive into asynchronous programming
 
Using assm in service object
Using assm in service object Using assm in service object
Using assm in service object
 
Intro to javascript (6:19)
Intro to javascript (6:19)Intro to javascript (6:19)
Intro to javascript (6:19)
 
Clustering and load balancing : jboss
Clustering and load balancing : jbossClustering and load balancing : jboss
Clustering and load balancing : jboss
 
Serverless in production, an experience report (LNUG)
Serverless in production, an experience report (LNUG)Serverless in production, an experience report (LNUG)
Serverless in production, an experience report (LNUG)
 
Rails 5 – Amsterdam.rb – Uberous
Rails 5 – Amsterdam.rb – UberousRails 5 – Amsterdam.rb – Uberous
Rails 5 – Amsterdam.rb – Uberous
 
Async/Await Best Practices
Async/Await Best PracticesAsync/Await Best Practices
Async/Await Best Practices
 
Serverless in Production, an experience report (cloudXchange)
Serverless in Production, an experience report (cloudXchange)Serverless in Production, an experience report (cloudXchange)
Serverless in Production, an experience report (cloudXchange)
 
Leveraging Micronaut on AWS Lambda
Leveraging Micronaut on AWS LambdaLeveraging Micronaut on AWS Lambda
Leveraging Micronaut on AWS Lambda
 
Lets build-ruby-app-server: Vineet tyagi
Lets build-ruby-app-server: Vineet tyagiLets build-ruby-app-server: Vineet tyagi
Lets build-ruby-app-server: Vineet tyagi
 
Javascript Workshop
Javascript WorkshopJavascript Workshop
Javascript Workshop
 
Async Programming in C# 5
Async Programming in C# 5Async Programming in C# 5
Async Programming in C# 5
 
Custom Mongrel Handlers: Learning how to walk the dog
Custom Mongrel Handlers: Learning how to walk the dogCustom Mongrel Handlers: Learning how to walk the dog
Custom Mongrel Handlers: Learning how to walk the dog
 

Similar to Qtp quiz for you

7400354 vbscript-in-qtp
7400354 vbscript-in-qtp7400354 vbscript-in-qtp
7400354 vbscript-in-qtp
Bharath003
 
String & path functions in vba
String & path functions in vbaString & path functions in vba
String & path functions in vba
gondwe Ben
 
Advanced+qtp+open+order
Advanced+qtp+open+orderAdvanced+qtp+open+order
Advanced+qtp+open+orderRamu Palanki
 
JavaScripts internals #1
JavaScripts internals #1JavaScripts internals #1
JavaScripts internals #1
Martin Pernica
 
Drilling the Async Library
Drilling the Async LibraryDrilling the Async Library
Drilling the Async Library
Knoldus Inc.
 
Javascript - Tutorial
Javascript - TutorialJavascript - Tutorial
Javascript - Tutorialadelaticleanu
 
Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]srikanthbkm
 
WORKING WITH FUNCTIONS
WORKING WITH FUNCTIONSWORKING WITH FUNCTIONS
WORKING WITH FUNCTIONS
PihuJha1
 
PVS-Studio team is about to produce a technical breakthrough, but for now let...
PVS-Studio team is about to produce a technical breakthrough, but for now let...PVS-Studio team is about to produce a technical breakthrough, but for now let...
PVS-Studio team is about to produce a technical breakthrough, but for now let...
PVS-Studio
 
Compose_camp_Day_1.pptx
Compose_camp_Day_1.pptxCompose_camp_Day_1.pptx
Compose_camp_Day_1.pptx
GanpatParmar1
 
C++ Tail Recursion Using 64-bit variables
C++ Tail Recursion Using 64-bit variablesC++ Tail Recursion Using 64-bit variables
C++ Tail Recursion Using 64-bit variables
PVS-Studio
 
Computer science notes of functions chapter
Computer science notes of functions chapterComputer science notes of functions chapter
Computer science notes of functions chapter
Godzilla33
 
Perf onjs final
Perf onjs finalPerf onjs final
Perf onjs finalqi yang
 
VB Script Overview
VB Script OverviewVB Script Overview
VB Script Overview
Praveen Gorantla
 
JavaScript Cheatsheets with easy way .pdf
JavaScript Cheatsheets with easy way .pdfJavaScript Cheatsheets with easy way .pdf
JavaScript Cheatsheets with easy way .pdf
ranjanadeore1
 
Lecture 4: Functions
Lecture 4: FunctionsLecture 4: Functions
Lecture 4: Functions
Vivek Bhargav
 
Aprendendo solid com exemplos
Aprendendo solid com exemplosAprendendo solid com exemplos
Aprendendo solid com exemplos
vinibaggio
 
Week 2.pptx
Week 2.pptxWeek 2.pptx
Week 2.pptx
WillSephton
 

Similar to Qtp quiz for you (20)

7400354 vbscript-in-qtp
7400354 vbscript-in-qtp7400354 vbscript-in-qtp
7400354 vbscript-in-qtp
 
String & path functions in vba
String & path functions in vbaString & path functions in vba
String & path functions in vba
 
Advanced+qtp+open+order
Advanced+qtp+open+orderAdvanced+qtp+open+order
Advanced+qtp+open+order
 
JavaScripts internals #1
JavaScripts internals #1JavaScripts internals #1
JavaScripts internals #1
 
Drilling the Async Library
Drilling the Async LibraryDrilling the Async Library
Drilling the Async Library
 
Javascript - Tutorial
Javascript - TutorialJavascript - Tutorial
Javascript - Tutorial
 
Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]
 
Unit 2.5
Unit 2.5Unit 2.5
Unit 2.5
 
WORKING WITH FUNCTIONS
WORKING WITH FUNCTIONSWORKING WITH FUNCTIONS
WORKING WITH FUNCTIONS
 
PVS-Studio team is about to produce a technical breakthrough, but for now let...
PVS-Studio team is about to produce a technical breakthrough, but for now let...PVS-Studio team is about to produce a technical breakthrough, but for now let...
PVS-Studio team is about to produce a technical breakthrough, but for now let...
 
Unit 2.5
Unit 2.5Unit 2.5
Unit 2.5
 
Compose_camp_Day_1.pptx
Compose_camp_Day_1.pptxCompose_camp_Day_1.pptx
Compose_camp_Day_1.pptx
 
C++ Tail Recursion Using 64-bit variables
C++ Tail Recursion Using 64-bit variablesC++ Tail Recursion Using 64-bit variables
C++ Tail Recursion Using 64-bit variables
 
Computer science notes of functions chapter
Computer science notes of functions chapterComputer science notes of functions chapter
Computer science notes of functions chapter
 
Perf onjs final
Perf onjs finalPerf onjs final
Perf onjs final
 
VB Script Overview
VB Script OverviewVB Script Overview
VB Script Overview
 
JavaScript Cheatsheets with easy way .pdf
JavaScript Cheatsheets with easy way .pdfJavaScript Cheatsheets with easy way .pdf
JavaScript Cheatsheets with easy way .pdf
 
Lecture 4: Functions
Lecture 4: FunctionsLecture 4: Functions
Lecture 4: Functions
 
Aprendendo solid com exemplos
Aprendendo solid com exemplosAprendendo solid com exemplos
Aprendendo solid com exemplos
 
Week 2.pptx
Week 2.pptxWeek 2.pptx
Week 2.pptx
 

More from Ramu Palanki

Qtp sample certification questions and answers
Qtp sample certification questions and answersQtp sample certification questions and answers
Qtp sample certification questions and answersRamu Palanki
 
Qtp realtime scripts
Qtp realtime scriptsQtp realtime scripts
Qtp realtime scriptsRamu Palanki
 
Qtp questions and answers
Qtp questions and answersQtp questions and answers
Qtp questions and answersRamu Palanki
 
Qtp material for beginners
Qtp material for beginnersQtp material for beginners
Qtp material for beginnersRamu Palanki
 
Qtp interview questions
Qtp interview questionsQtp interview questions
Qtp interview questionsRamu Palanki
 
Qtp interview questions and answers
Qtp interview questions and answersQtp interview questions and answers
Qtp interview questions and answersRamu Palanki
 
Qtp interview questions3
Qtp interview questions3Qtp interview questions3
Qtp interview questions3Ramu Palanki
 
Qtp complete guide for all
Qtp complete guide for allQtp complete guide for all
Qtp complete guide for allRamu Palanki
 
Qtp compare two xml files
Qtp compare two xml filesQtp compare two xml files
Qtp compare two xml filesRamu Palanki
 
Qtp change excel cell color with condition
Qtp change excel cell color with conditionQtp change excel cell color with condition
Qtp change excel cell color with conditionRamu Palanki
 
Qtp certification questions
Qtp certification questionsQtp certification questions
Qtp certification questionsRamu Palanki
 
Qtp certification questions and tutorial
Qtp certification questions and tutorialQtp certification questions and tutorial
Qtp certification questions and tutorialRamu Palanki
 
Qtp certification questions2
Qtp certification questions2Qtp certification questions2
Qtp certification questions2Ramu Palanki
 
Qtp automation estimation techniques
Qtp automation estimation techniquesQtp automation estimation techniques
Qtp automation estimation techniquesRamu Palanki
 
Qtp 11 new enhacements in
Qtp 11 new enhacements inQtp 11 new enhacements in
Qtp 11 new enhacements inRamu Palanki
 
Qtp passing parameters between actions
Qtp passing parameters between actionsQtp passing parameters between actions
Qtp passing parameters between actionsRamu Palanki
 

More from Ramu Palanki (20)

Qtp sample certification questions and answers
Qtp sample certification questions and answersQtp sample certification questions and answers
Qtp sample certification questions and answers
 
Qtp realtime scripts
Qtp realtime scriptsQtp realtime scripts
Qtp realtime scripts
 
Qtp questions and answers
Qtp questions and answersQtp questions and answers
Qtp questions and answers
 
Qtp presentation
Qtp presentationQtp presentation
Qtp presentation
 
Qtp material for beginners
Qtp material for beginnersQtp material for beginners
Qtp material for beginners
 
Qtp interview questions
Qtp interview questionsQtp interview questions
Qtp interview questions
 
Qtp interview questions and answers
Qtp interview questions and answersQtp interview questions and answers
Qtp interview questions and answers
 
Qtp interview questions3
Qtp interview questions3Qtp interview questions3
Qtp interview questions3
 
Qtp complete guide for all
Qtp complete guide for allQtp complete guide for all
Qtp complete guide for all
 
Qtp compare two xml files
Qtp compare two xml filesQtp compare two xml files
Qtp compare two xml files
 
Qtp change excel cell color with condition
Qtp change excel cell color with conditionQtp change excel cell color with condition
Qtp change excel cell color with condition
 
Qtp certification questions
Qtp certification questionsQtp certification questions
Qtp certification questions
 
Qtp certification questions and tutorial
Qtp certification questions and tutorialQtp certification questions and tutorial
Qtp certification questions and tutorial
 
Qtp certification questions2
Qtp certification questions2Qtp certification questions2
Qtp certification questions2
 
Qtp best tutorial
Qtp best tutorialQtp best tutorial
Qtp best tutorial
 
Qtp basic stuff
Qtp basic stuffQtp basic stuff
Qtp basic stuff
 
Qtp automation estimation techniques
Qtp automation estimation techniquesQtp automation estimation techniques
Qtp automation estimation techniques
 
Qtp 11 new enhacements in
Qtp 11 new enhacements inQtp 11 new enhacements in
Qtp 11 new enhacements in
 
Qtp sample resume
Qtp sample resumeQtp sample resume
Qtp sample resume
 
Qtp passing parameters between actions
Qtp passing parameters between actionsQtp passing parameters between actions
Qtp passing parameters between actions
 

Qtp quiz for you

  • 1. for more QTP scripts, visit www.ramupalanki.com 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? Technorati Tags: hp qtp,qtp quiz,by value,by reference
  • 2. for more QTP scripts, visit www.ramupalanki.com I'm sure you have already subscribed to our feed but just in case not. I recommend you to subscribe via RSS feed. You can also subscribe by Email and have new QTP articles sent directly to your inbox. Related posts: 1. Quiz: A message box that will close automatically 2. Quiz: Find the difference between these VBScript codes? 3. How to load a DLL with QTP? 7 comments ↓ #1 Percy Bell on 11.03.08 at 7:17 am A: jain jain B: ankur jain Passing by Value is just that. It passes a value to the function to use. It creates a new space to hold this value. Passing by Reference passes the pointer to the memory space for the variable. This means that anything you do to the variable in the function changes the actual value of the passed variable. This means that if you changed the variable in the function it will be changed outside the function too. #2 Zecty on 11.03.08 at 10:11 am The output will be different. The first code (byRef), will output the name “jain” twice. Because, when a variable is passed by reference, both the variable “var” (passed as a parameter) and “myname” (used inside the function) will point to the same memory space. Since “myname” was not declared (“dim”) inside the function, when a variable is passed by reference in vbscript, use of the variable name refers to the calling scope’s use of the variable. But when passed by value (byVal), the “myname” variable used inside the function and the “var” parameter, will both be ‘local variables’ that are instantiated only for the life of the function, and do not affect the memory area used by the ‘global’ “myname” variable. This shows why it is a good reason to always declare variables!
  • 3. for more QTP scripts, visit www.ramupalanki.com