SlideShare a Scribd company logo
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 (20)

PPTX
Qtp vb scripting
Bharath Sannadi
 
PPTX
VB Script
Satish Sukumaran
 
PPTX
Vbscript
Abhishek Kesharwani
 
PPT
VB Script Overview
Praveen Gorantla
 
PDF
7400354 vbscript-in-qtp
Bharath003
 
PDF
Vbs
santosh_axle
 
DOCX
VBScript Functions procedures and arrays.docx
Ramakrishna Reddy Bijjam
 
PPT
Qtp - Introduction to fundamentals of vbscript
Vibrant Technologies & Computers
 
PPT
Vb script
Aamir Sohail
 
PPTX
Array and functions
Sun Technlogies
 
PPT
Vb script
mcatahir947
 
PDF
Vb script tutorial
Abhishek Kesharwani
 
PPSX
VBScript in Software Testing
Fayis-QA
 
DOC
Advanced Qtp Book
G.C Reddy
 
PPT
Vbscript
VARSHAKUMARI49
 
DOC
Qtp Scripts
G.C Reddy
 
PDF
Advanced Qtp Book
guestd9317c
 
DOC
Advanced+qtp+open+order
Ramu Palanki
 
DOCX
Vb script tutorial
Abhishek Kesharwani
 
DOC
Vb Script Course For Qa
venkatunnam
 
Qtp vb scripting
Bharath Sannadi
 
VB Script
Satish Sukumaran
 
VB Script Overview
Praveen Gorantla
 
7400354 vbscript-in-qtp
Bharath003
 
VBScript Functions procedures and arrays.docx
Ramakrishna Reddy Bijjam
 
Qtp - Introduction to fundamentals of vbscript
Vibrant Technologies & Computers
 
Vb script
Aamir Sohail
 
Array and functions
Sun Technlogies
 
Vb script
mcatahir947
 
Vb script tutorial
Abhishek Kesharwani
 
VBScript in Software Testing
Fayis-QA
 
Advanced Qtp Book
G.C Reddy
 
Vbscript
VARSHAKUMARI49
 
Qtp Scripts
G.C Reddy
 
Advanced Qtp Book
guestd9317c
 
Advanced+qtp+open+order
Ramu Palanki
 
Vb script tutorial
Abhishek Kesharwani
 
Vb Script Course For Qa
venkatunnam
 

Recently uploaded (20)

PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Ad

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.