SlideShare a Scribd company logo
1 of 24
BASIC VBSCRIPT FOR QTP
Basic vbscript functions which are used in QTP
VBSCRIPT IN QTP
 Scripting language for QuickTest Professional
(QTP) is VBScript.
 VBScript is a light version of Microsoft's
programming language Visual Basic.
 VBScript source code is contained in stand-alone
files, they have the file extension .vbs.
AGENDA
1. VBScript Variable
2. VBScript Array Variable
3. VBScript Functions and Subroutines
4. VBScript Conditional Statements
5. VBScript Looping Statements
6. VBScript Date and Time Functions
7. VBScript Built-in Functions
8. VBScript Classes
1. VBSCRIPT VARIABLE
 In VBScript all variables are of the type variant that
can store any type of value.
 Rules for VBScript variable name:
 Must begin with a letter
 Cannot contain period (.)
 Cannot exceed 255 characters
 It must be distinctive (unique) within the scope in
which it is declared.
 E.x: Dim b
b = 100
Function TEST()
Dim a,b
a = 1
b = 2
MsgBox a + b
End Function
TEST
MsgBox b
1. VBSCRIPT VARIABLE (CONT.)
 Variables can be declared explicitly and implicitly.
 Explicitly variables are declared with Dim
statement, Public statement, Private statement.
 Dim Name
 Dim Name, employee_address, city
 Implicitly we can declare them within the script by
just using the variable name. But this practice is
prone to errors.
 We can compel VBScript to require all variables to
be explicitly declared by including the statement
Option Explicit at the start of every script.
 Variable can be declared as constants (Const).
2. VBSCRIPT ARRAY VARIABLE
 Every element of an array is associated with a unique
index number. By default, index number starts from 0.
The number of elements in an array is a fixed number. It
can also be re-adjusted dynamically.
 VBScript supports up to 60 dimensions in an array.
 Structure:
 Dim variable_name()
 ReDim [Preserve] variable_name(new_limit)
 The first, we declare an array with no upper limit
 The 2nd, with ReDim we reset the upper bound to a new
value. The optional key word "Preserve" states that all of
the old elements must be preserved when changing the
array size.
2. VBSCRIPT ARRAY VARIABLE (CONT.)
 Example:
 Dim First_Array() 'dynamic array
 ReDim First_Array(25) 'ReDim sets the initial size of the
dynamic array to 25
 ReDim First_Array(2) 'We can resize a dynamic array unlimited
number of times
 'Put data to Array
First_Array(0) = “1”
First_Array(1) = “2”
First_Array(2) = “3”
 ReDim Preserve First_Array(5) 'Resize the array, but keep the
existing data
MsgBox First_Array(2) ‘=> MsgBox displays 3
 Dim arr
arr = Array(5,10,15,20)
2. VBSCRIPT ARRAY VARIABLE (CONT.)
 Some of the Array keywords and their uses:
Keyword Function
Dim It will Declare an array
ReDim This is used to size or resize a dynamic array.
IsArray Will Return True if A is an array, False if it is not
LBound Will Return lower bound of an array, in VBScript it
always returns 0
UBound Will Return an upper bound of array
Preserve (Optional) is used to preserve the data in an
existing array when you resize it.
Erase Reinitializes the elements if it is a fixed-size array
and deallocates the memory used if it is a
dynamic array.
3. VBSCRIPT FUNCTIONS AND SUBROUTINES
 A Sub procedure:
 is a series of statements, enclosed by the Sub and End Sub
statements
 can perform actions, but does not return a value
 can take arguments
 A Function procedure:
 is a series of statements, enclosed by the Function and End Function
statements
 can perform actions and can return a value
 can take arguments that are passed to it by a calling procedure
 without arguments, must include an empty set of parentheses ()
 returns a value by assigning a value to its name
3. VBSCRIPT FUNCTIONS AND SUBROUTINES
(CONT.)
 The main difference between a function and a
subroutine is that a subroutine will do some
processing of the code and then quit, while a
function processes some code and then returns the
result back.
 Calling a Procedure:
• Call a Sub • Call a Funtion
4. VBSCRIPT CONDITIONAL STATEMENTS
 In VBScript we have 4 conditional statements:
 If statement - executes a set of code when a condition is true
 If...Then...Else statement - select one of two sets of lines to
execute
 If...Then...ElseIf statement - select one of many sets of lines to
execute
 Select Case statement - select one of many sets of lines to
execute
 Example:
5. VBSCRIPT LOOPING STATEMENTS
 In VBScript we have four looping statements:
 For...Next statement - runs code a specified number of
times
 For Each...Next statement - runs code for each item in
a collection or each element of an array
 Do...Loop statement - loops while or until a condition is
true
 While...Wend statement – loops while a condition is
true. (recommend to do not use this statement, use the
Do…Loop instead)
 Example:
5. VBSCRIPT LOOPING STATEMENTS (CONT.)
1. For … Next
 With the help of Step keyword, we can increase or decrease
the counter by the value specified.
 You can exit a For...Next statement with the Exit For keyword.
5. VBSCRIPT LOOPING STATEMENTS (CONT.)
2. For Each … Next
 A For Each...Next loop repeats a block of code for each item
in a collection, or for each element of an array.
 It is useful when we don’t know how many elements are
there in the dynamic array.
5. VBSCRIPT LOOPING STATEMENTS (CONT.)
3. Do … Loop
 It will repeat a block of code while a condition is True or until a
condition becomes True
 You can exit a Do...Loop statement with the Exit Do keyword.
5. VBSCRIPT LOOPING STATEMENTS (CONT.)
4. While … Wend
 While Loop is a simple loop that keeps looping while a condition
is true
 While...Wend loops can be nested to any level.
Each Wend matches the most recent While.
 The Do...Loop statement provides a more structured and
flexible way to perform looping. Should use it instead.
6. VBSCRIPT DATE AND TIME FUNCTIONS
 Date()
 Time()
 Weekday()
 WeekdayName()
6. VBSCRIPT DATE AND TIME FUNCTIONS
(CONT.)
 Month()
 MonthName()
 DateDiff()
6. VBSCRIPT DATE AND TIME FUNCTIONS
(CONT.)
 FormatDateTime()
 IsDate()
7. VBSCRIPT BUILT-IN FUNCTIONS
 Ucase()
 Lcase()
 Trim()
 Ltrim()
 Rtrim()
 StrReverse()
7. VBSCRIPT BUILT-IN FUNCTIONS (CONT.)
 Round()
 Randomize()
 Left()
 Right()
7. VBSCRIPT BUILT-IN FUNCTIONS (CONT.)
 Replace()
 Mid()
 Split()
8. VBSCRIPT CLASSES
 Above we have created a class (Hello_World) and an instance
(MyHello_World) of that class. VBScript uses the Class...End
Class statements to define the contents of the class. The
property (Location) and procedure (Say_Hello) are also declared
within the class.
 Members within the class can be declared as private and public.
Private members are only visible within the class whereas public
members are accessible by any code outside of the class. Public
is default.
 Procedures (Sub or Function) declared Public within the class
are methods of the class. Public variables serve as properties of
the class.
THANK YOU!

More Related Content

Similar to Basic vbscript for qtp

Advanced+qtp+open+order
Advanced+qtp+open+orderAdvanced+qtp+open+order
Advanced+qtp+open+order
Ramu Palanki
 
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
 

Similar to Basic vbscript for qtp (20)

7400354 vbscript-in-qtp
7400354 vbscript-in-qtp7400354 vbscript-in-qtp
7400354 vbscript-in-qtp
 
VB Script Overview
VB Script OverviewVB Script Overview
VB Script Overview
 
Vbs
VbsVbs
Vbs
 
Advanced+qtp+open+order
Advanced+qtp+open+orderAdvanced+qtp+open+order
Advanced+qtp+open+order
 
Vbscript
VbscriptVbscript
Vbscript
 
Advanced Qtp Book
Advanced Qtp BookAdvanced Qtp Book
Advanced Qtp Book
 
VB Script
VB ScriptVB Script
VB Script
 
Advanced Qtp Book
Advanced Qtp BookAdvanced Qtp Book
Advanced Qtp Book
 
Array and functions
Array and functionsArray and functions
Array and functions
 
Vb script tutorial
Vb script tutorialVb script tutorial
Vb script tutorial
 
Qtp Scripts
Qtp ScriptsQtp Scripts
Qtp Scripts
 
Typescript Basics
Typescript BasicsTypescript Basics
Typescript Basics
 
Qtp vb scripting
Qtp vb scriptingQtp vb scripting
Qtp vb scripting
 
Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]
 
Vb script tutorial
Vb script tutorialVb script tutorial
Vb script tutorial
 
Vb script final pari
Vb script final pariVb script final pari
Vb script final pari
 
Javascripts hidden treasures BY - https://geekyants.com/
Javascripts hidden treasures            BY  -  https://geekyants.com/Javascripts hidden treasures            BY  -  https://geekyants.com/
Javascripts hidden treasures BY - https://geekyants.com/
 
VBScript in Software Testing
VBScript in Software TestingVBScript in Software Testing
VBScript in Software Testing
 
Embedded c
Embedded cEmbedded c
Embedded c
 
Litwin linq
Litwin linqLitwin linq
Litwin linq
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 

Basic vbscript for qtp

  • 1. BASIC VBSCRIPT FOR QTP Basic vbscript functions which are used in QTP
  • 2. VBSCRIPT IN QTP  Scripting language for QuickTest Professional (QTP) is VBScript.  VBScript is a light version of Microsoft's programming language Visual Basic.  VBScript source code is contained in stand-alone files, they have the file extension .vbs.
  • 3. AGENDA 1. VBScript Variable 2. VBScript Array Variable 3. VBScript Functions and Subroutines 4. VBScript Conditional Statements 5. VBScript Looping Statements 6. VBScript Date and Time Functions 7. VBScript Built-in Functions 8. VBScript Classes
  • 4. 1. VBSCRIPT VARIABLE  In VBScript all variables are of the type variant that can store any type of value.  Rules for VBScript variable name:  Must begin with a letter  Cannot contain period (.)  Cannot exceed 255 characters  It must be distinctive (unique) within the scope in which it is declared.  E.x: Dim b b = 100 Function TEST() Dim a,b a = 1 b = 2 MsgBox a + b End Function TEST MsgBox b
  • 5. 1. VBSCRIPT VARIABLE (CONT.)  Variables can be declared explicitly and implicitly.  Explicitly variables are declared with Dim statement, Public statement, Private statement.  Dim Name  Dim Name, employee_address, city  Implicitly we can declare them within the script by just using the variable name. But this practice is prone to errors.  We can compel VBScript to require all variables to be explicitly declared by including the statement Option Explicit at the start of every script.  Variable can be declared as constants (Const).
  • 6. 2. VBSCRIPT ARRAY VARIABLE  Every element of an array is associated with a unique index number. By default, index number starts from 0. The number of elements in an array is a fixed number. It can also be re-adjusted dynamically.  VBScript supports up to 60 dimensions in an array.  Structure:  Dim variable_name()  ReDim [Preserve] variable_name(new_limit)  The first, we declare an array with no upper limit  The 2nd, with ReDim we reset the upper bound to a new value. The optional key word "Preserve" states that all of the old elements must be preserved when changing the array size.
  • 7. 2. VBSCRIPT ARRAY VARIABLE (CONT.)  Example:  Dim First_Array() 'dynamic array  ReDim First_Array(25) 'ReDim sets the initial size of the dynamic array to 25  ReDim First_Array(2) 'We can resize a dynamic array unlimited number of times  'Put data to Array First_Array(0) = “1” First_Array(1) = “2” First_Array(2) = “3”  ReDim Preserve First_Array(5) 'Resize the array, but keep the existing data MsgBox First_Array(2) ‘=> MsgBox displays 3  Dim arr arr = Array(5,10,15,20)
  • 8. 2. VBSCRIPT ARRAY VARIABLE (CONT.)  Some of the Array keywords and their uses: Keyword Function Dim It will Declare an array ReDim This is used to size or resize a dynamic array. IsArray Will Return True if A is an array, False if it is not LBound Will Return lower bound of an array, in VBScript it always returns 0 UBound Will Return an upper bound of array Preserve (Optional) is used to preserve the data in an existing array when you resize it. Erase Reinitializes the elements if it is a fixed-size array and deallocates the memory used if it is a dynamic array.
  • 9. 3. VBSCRIPT FUNCTIONS AND SUBROUTINES  A Sub procedure:  is a series of statements, enclosed by the Sub and End Sub statements  can perform actions, but does not return a value  can take arguments  A Function procedure:  is a series of statements, enclosed by the Function and End Function statements  can perform actions and can return a value  can take arguments that are passed to it by a calling procedure  without arguments, must include an empty set of parentheses ()  returns a value by assigning a value to its name
  • 10. 3. VBSCRIPT FUNCTIONS AND SUBROUTINES (CONT.)  The main difference between a function and a subroutine is that a subroutine will do some processing of the code and then quit, while a function processes some code and then returns the result back.  Calling a Procedure: • Call a Sub • Call a Funtion
  • 11. 4. VBSCRIPT CONDITIONAL STATEMENTS  In VBScript we have 4 conditional statements:  If statement - executes a set of code when a condition is true  If...Then...Else statement - select one of two sets of lines to execute  If...Then...ElseIf statement - select one of many sets of lines to execute  Select Case statement - select one of many sets of lines to execute  Example:
  • 12. 5. VBSCRIPT LOOPING STATEMENTS  In VBScript we have four looping statements:  For...Next statement - runs code a specified number of times  For Each...Next statement - runs code for each item in a collection or each element of an array  Do...Loop statement - loops while or until a condition is true  While...Wend statement – loops while a condition is true. (recommend to do not use this statement, use the Do…Loop instead)  Example:
  • 13. 5. VBSCRIPT LOOPING STATEMENTS (CONT.) 1. For … Next  With the help of Step keyword, we can increase or decrease the counter by the value specified.  You can exit a For...Next statement with the Exit For keyword.
  • 14. 5. VBSCRIPT LOOPING STATEMENTS (CONT.) 2. For Each … Next  A For Each...Next loop repeats a block of code for each item in a collection, or for each element of an array.  It is useful when we don’t know how many elements are there in the dynamic array.
  • 15. 5. VBSCRIPT LOOPING STATEMENTS (CONT.) 3. Do … Loop  It will repeat a block of code while a condition is True or until a condition becomes True  You can exit a Do...Loop statement with the Exit Do keyword.
  • 16. 5. VBSCRIPT LOOPING STATEMENTS (CONT.) 4. While … Wend  While Loop is a simple loop that keeps looping while a condition is true  While...Wend loops can be nested to any level. Each Wend matches the most recent While.  The Do...Loop statement provides a more structured and flexible way to perform looping. Should use it instead.
  • 17. 6. VBSCRIPT DATE AND TIME FUNCTIONS  Date()  Time()  Weekday()  WeekdayName()
  • 18. 6. VBSCRIPT DATE AND TIME FUNCTIONS (CONT.)  Month()  MonthName()  DateDiff()
  • 19. 6. VBSCRIPT DATE AND TIME FUNCTIONS (CONT.)  FormatDateTime()  IsDate()
  • 20. 7. VBSCRIPT BUILT-IN FUNCTIONS  Ucase()  Lcase()  Trim()  Ltrim()  Rtrim()  StrReverse()
  • 21. 7. VBSCRIPT BUILT-IN FUNCTIONS (CONT.)  Round()  Randomize()  Left()  Right()
  • 22. 7. VBSCRIPT BUILT-IN FUNCTIONS (CONT.)  Replace()  Mid()  Split()
  • 23. 8. VBSCRIPT CLASSES  Above we have created a class (Hello_World) and an instance (MyHello_World) of that class. VBScript uses the Class...End Class statements to define the contents of the class. The property (Location) and procedure (Say_Hello) are also declared within the class.  Members within the class can be declared as private and public. Private members are only visible within the class whereas public members are accessible by any code outside of the class. Public is default.  Procedures (Sub or Function) declared Public within the class are methods of the class. Public variables serve as properties of the class.