SlideShare a Scribd company logo
QTP – VB Scripting
What is VBScript?
What is VBScript?
•VBScript is a scripting language
•A scripting language is a lightweight programming language
•VBScript is a light version of Microsoft's programming language Visual Basic
•VBScript is the default language in ASP (Active Server Pages)
VBScript Variables
VBScript variables are used to hold values or expressions.
A variable can have a short name, like x, or a more descriptive name, like carname.
Rules for VBScript variable names:
-> Must begin with a letter
-> Cannot contain a period (.)
-> Cannot exceed 255 characters
In VBScript, all variables are of type variant, that can store different types of data.
VBScript Variables
Declaring (Creating) VBScript Variables
Dim x
Dim carname
Assigning Values to Variables
carname="Volvo"
VBScript Arrays
An array variable is used to store multiple values in a single variable.
Creating Arrays in VB Scripting
Dim names(2)
Adding values into an Array :
names(0)="Tove"
names(1)="Jani"
names(2)="Stale"
Reading Values from an Array :
mother=names(0)
Creating Two Dimensional Array
Dim names(2,2)
Adding values into an Array :
names(0,0)="Tove"
names(0,1)="Jani"
names(1,0)="Stale"
names(1,0)="Stale"
Reading Values from an Array :
mother=names(0,0)
VB - Option Explicit
Option Explicit
Dim carname
carname=some value
This statement forces you to declare all your variables with the dim
If you misspell for example the "carname" variable to "carnime", the script will automatically create a
new variable called "carnime".
To prevent your script from doing this, you can use the Option Explicit statement.
VB - Functions
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
Syntax for Creating Functions:
function myfunction(A, B)
myfunction= A + B
end function
Syntax for Calling Function:
Call myfunction(argument)
VB - Sub procedure
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
Example :
Sub mysub(argument1,argument2)
some statements
End Sub
Syntax for Calling Sub:
Mysub argument
VB – Conditional Statements
Conditional statements are used to perform different actions for different decisions.
In VBScript we have four 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
VB – Conditional Statements
Syntax If Statement :
If i = 10 Then
some statements
ElseIf i = 11 Then
some statements
ElseIf i = 12 Then
some statements
Else
some statements
End If
Syntax Select Statement:
Select Case d
Case 1
some statements
Case 2
some statements
Case else
some statements
End Select
VB – Looping Statements
Looping statements are used to run the same block of code a specified number of times.
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 - Do not use it - use the Do...Loop statement instead
VB – Looping Statements
Syntax for Loop:
For i=2 To 10
some code
Next
Exit a For...Next
You can exit a For...Next statement with the Exit For keyword.
For i=1 To 10
If i=5 Then
some code
Exit For
End If
Next
VB – String Functions
Function Description
InStr Returns the position of the first occurrence of one string within another. The search begins at
the first character of the string
InStrRev Returns the position of the first occurrence of one string within another. The search begins at
the last character of the string
LCase Converts a specified string to lowercase
Left Returns a specified number of characters from the left side of a string
Len Returns the number of characters in a string
LTrim Removes spaces on the left side of a string
RTrim Removes spaces on the right side of a string
Trim Removes spaces on both the left and the right side of a string
VB – String Functions
Mid Returns a specified number of characters from a string
Replace Replaces a specified part of a string with another string a specified number of times
Right Returns a specified number of characters from the right side of a string
Space Returns a string that consists of a specified number of spaces
StrComp Compares two strings and returns a value that represents the result of the comparison
String Returns a string that contains a repeating character of a specified length
StrReverse Reverses a string
UCase Converts a specified string to uppercase
VB – Array Functions
Function Description
Array Returns a variant containing an array
Filter Returns a zero-based array that contains a subset of a string array based on a filter
criteria
IsArray Returns a Boolean value that indicates whether a specified variable is an array
Join Returns a string that consists of a number of substrings in an array
LBound Returns the smallest subscript for the indicated dimension of an array
Split Returns a zero-based, one-dimensional array that contains a specified number of
substrings
UBound Returns the largest subscript for the indicated dimension of an array
VB – Date Functions
Function Description
CDate Converts a valid date and time expression to the variant of subtype Date
Date Returns the current system date
DateAdd Returns a date to which a specified time interval has been added
Day Returns a number that represents the day of the month (between 1 and 31,
inclusive)
FormatDateTime Returns an expression formatted as a date or time
Hour Returns a number that represents the hour of the day (between 0 and 23,
inclusive)
IsDate Returns a Boolean value that indicates if the evaluated expression can be
converted to a date
VB – Date Functions
Minute Returns a number that represents the minute of the hour (between 0 and 59,
inclusive)
Month Returns a number that represents the month of the year (between 1 and 12, inclusive)
MonthName Returns the name of a specified month
Now Returns the current system date and time
Second Returns a number that represents the second of the minute (between 0 and 59,
inclusive)
Time Returns the current system time
TimeValue Returns a time
Weekday Returns a number that represents the day of the week (between 1 and 7, inclusive)
Year Returns a number that represents the year

More Related Content

PPT
Strings
PPTX
Compiler: Programming Language= Assignments and statements
ODP
Shapeless- Generic programming for Scala
PPT
PPTX
Strings in c++
PDF
2 variables and data types
PPTX
Strings in programming tutorial.
PPTX
Strings in C
Strings
Compiler: Programming Language= Assignments and statements
Shapeless- Generic programming for Scala
Strings in c++
2 variables and data types
Strings in programming tutorial.
Strings in C

What's hot (20)

PPTX
String in c programming
PPTX
Handling of character strings C programming
PPTX
Finite automata-for-lexical-analysis
PDF
String.ppt
PPTX
PPT
Operation on string presentation
PDF
Strings in c language
PPT
02 functions, variables, basic input and output of c++
PPTX
String C Programming
PPTX
C programming - String
PDF
Strings IN C
DOC
String in c
ODP
Functors, Applicatives and Monads In Scala
PDF
Chapter 7 expressions and assignment statements ii
PPT
Assembly Language String Chapter
PPTX
String in programming language in c or c++
PPTX
Implementation Of String Functions In C
PDF
Manipulating strings
PPT
Strings
String in c programming
Handling of character strings C programming
Finite automata-for-lexical-analysis
String.ppt
Operation on string presentation
Strings in c language
02 functions, variables, basic input and output of c++
String C Programming
C programming - String
Strings IN C
String in c
Functors, Applicatives and Monads In Scala
Chapter 7 expressions and assignment statements ii
Assembly Language String Chapter
String in programming language in c or c++
Implementation Of String Functions In C
Manipulating strings
Strings
Ad

Viewers also liked (9)

DOC
Learn VbScript -String Functions
DOC
vbscripting
PDF
Vb script reference
PDF
VBScript Tutorial
PPT
Vb script
PPT
vb script
PPT
Intorudction into VBScript
PDF
Dotnet differences compiled -1
PPTX
VB Script
Learn VbScript -String Functions
vbscripting
Vb script reference
VBScript Tutorial
Vb script
vb script
Intorudction into VBScript
Dotnet differences compiled -1
VB Script
Ad

Similar to Qtp vb scripting (20)

PPTX
Vb script final pari
PPTX
Basic vbscript for qtp
PDF
7400354 vbscript-in-qtp
PDF
Vizwik Coding Manual
PPTX
PPTX
C_plus_plus
PPT
VB Script Overview
PPTX
JavaScript.pptx
PPT
Of Lambdas and LINQ
PPSX
VBScript in Software Testing
PDF
Vb script tutorial
PPT
From UML/OCL to natural language (using SBVR as pivot)
DOC
Advanced+qtp+open+order
DOCX
C# language basics (Visual Studio)
DOCX
C# language basics (Visual studio)
PPTX
unit 1 (1).pptx
PPTX
the various Excel Functions in powerpoint format.pptx
PDF
12 computer science_notes_ch01_overview_of_cpp
PPTX
Python Programming Basics for begginners
PPTX
JavaScript – ECMAScript Basics By Satyen
Vb script final pari
Basic vbscript for qtp
7400354 vbscript-in-qtp
Vizwik Coding Manual
C_plus_plus
VB Script Overview
JavaScript.pptx
Of Lambdas and LINQ
VBScript in Software Testing
Vb script tutorial
From UML/OCL to natural language (using SBVR as pivot)
Advanced+qtp+open+order
C# language basics (Visual Studio)
C# language basics (Visual studio)
unit 1 (1).pptx
the various Excel Functions in powerpoint format.pptx
12 computer science_notes_ch01_overview_of_cpp
Python Programming Basics for begginners
JavaScript – ECMAScript Basics By Satyen

Recently uploaded (20)

PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Lesson notes of climatology university.
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Pharma ospi slides which help in ospi learning
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Presentation on HIE in infants and its manifestations
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
A systematic review of self-coping strategies used by university students to ...
2.FourierTransform-ShortQuestionswithAnswers.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Lesson notes of climatology university.
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Pharma ospi slides which help in ospi learning
O5-L3 Freight Transport Ops (International) V1.pdf
Presentation on HIE in infants and its manifestations
Abdominal Access Techniques with Prof. Dr. R K Mishra
O7-L3 Supply Chain Operations - ICLT Program
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Anesthesia in Laparoscopic Surgery in India
GDM (1) (1).pptx small presentation for students
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Module 4: Burden of Disease Tutorial Slides S2 2025
Microbial diseases, their pathogenesis and prophylaxis
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
A systematic review of self-coping strategies used by university students to ...

Qtp vb scripting

  • 1. QTP – VB Scripting
  • 2. What is VBScript? What is VBScript? •VBScript is a scripting language •A scripting language is a lightweight programming language •VBScript is a light version of Microsoft's programming language Visual Basic •VBScript is the default language in ASP (Active Server Pages)
  • 3. VBScript Variables VBScript variables are used to hold values or expressions. A variable can have a short name, like x, or a more descriptive name, like carname. Rules for VBScript variable names: -> Must begin with a letter -> Cannot contain a period (.) -> Cannot exceed 255 characters In VBScript, all variables are of type variant, that can store different types of data.
  • 4. VBScript Variables Declaring (Creating) VBScript Variables Dim x Dim carname Assigning Values to Variables carname="Volvo"
  • 5. VBScript Arrays An array variable is used to store multiple values in a single variable. Creating Arrays in VB Scripting Dim names(2) Adding values into an Array : names(0)="Tove" names(1)="Jani" names(2)="Stale" Reading Values from an Array : mother=names(0) Creating Two Dimensional Array Dim names(2,2) Adding values into an Array : names(0,0)="Tove" names(0,1)="Jani" names(1,0)="Stale" names(1,0)="Stale" Reading Values from an Array : mother=names(0,0)
  • 6. VB - Option Explicit Option Explicit Dim carname carname=some value This statement forces you to declare all your variables with the dim If you misspell for example the "carname" variable to "carnime", the script will automatically create a new variable called "carnime". To prevent your script from doing this, you can use the Option Explicit statement.
  • 7. VB - Functions 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 Syntax for Creating Functions: function myfunction(A, B) myfunction= A + B end function Syntax for Calling Function: Call myfunction(argument)
  • 8. VB - Sub procedure 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 Example : Sub mysub(argument1,argument2) some statements End Sub Syntax for Calling Sub: Mysub argument
  • 9. VB – Conditional Statements Conditional statements are used to perform different actions for different decisions. In VBScript we have four 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
  • 10. VB – Conditional Statements Syntax If Statement : If i = 10 Then some statements ElseIf i = 11 Then some statements ElseIf i = 12 Then some statements Else some statements End If Syntax Select Statement: Select Case d Case 1 some statements Case 2 some statements Case else some statements End Select
  • 11. VB – Looping Statements Looping statements are used to run the same block of code a specified number of times. 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 - Do not use it - use the Do...Loop statement instead
  • 12. VB – Looping Statements Syntax for Loop: For i=2 To 10 some code Next Exit a For...Next You can exit a For...Next statement with the Exit For keyword. For i=1 To 10 If i=5 Then some code Exit For End If Next
  • 13. VB – String Functions Function Description InStr Returns the position of the first occurrence of one string within another. The search begins at the first character of the string InStrRev Returns the position of the first occurrence of one string within another. The search begins at the last character of the string LCase Converts a specified string to lowercase Left Returns a specified number of characters from the left side of a string Len Returns the number of characters in a string LTrim Removes spaces on the left side of a string RTrim Removes spaces on the right side of a string Trim Removes spaces on both the left and the right side of a string
  • 14. VB – String Functions Mid Returns a specified number of characters from a string Replace Replaces a specified part of a string with another string a specified number of times Right Returns a specified number of characters from the right side of a string Space Returns a string that consists of a specified number of spaces StrComp Compares two strings and returns a value that represents the result of the comparison String Returns a string that contains a repeating character of a specified length StrReverse Reverses a string UCase Converts a specified string to uppercase
  • 15. VB – Array Functions Function Description Array Returns a variant containing an array Filter Returns a zero-based array that contains a subset of a string array based on a filter criteria IsArray Returns a Boolean value that indicates whether a specified variable is an array Join Returns a string that consists of a number of substrings in an array LBound Returns the smallest subscript for the indicated dimension of an array Split Returns a zero-based, one-dimensional array that contains a specified number of substrings UBound Returns the largest subscript for the indicated dimension of an array
  • 16. VB – Date Functions Function Description CDate Converts a valid date and time expression to the variant of subtype Date Date Returns the current system date DateAdd Returns a date to which a specified time interval has been added Day Returns a number that represents the day of the month (between 1 and 31, inclusive) FormatDateTime Returns an expression formatted as a date or time Hour Returns a number that represents the hour of the day (between 0 and 23, inclusive) IsDate Returns a Boolean value that indicates if the evaluated expression can be converted to a date
  • 17. VB – Date Functions Minute Returns a number that represents the minute of the hour (between 0 and 59, inclusive) Month Returns a number that represents the month of the year (between 1 and 12, inclusive) MonthName Returns the name of a specified month Now Returns the current system date and time Second Returns a number that represents the second of the minute (between 0 and 59, inclusive) Time Returns the current system time TimeValue Returns a time Weekday Returns a number that represents the day of the week (between 1 and 7, inclusive) Year Returns a number that represents the year