SlideShare a Scribd company logo
VBScript in QTP 
Microsoft VBScript (Visual Basic Script) is a general-purpose, lightweight , scripting language developed 
by Microsoft which is modeled on Visual Basic. VBScript is the main scripting language for Quick Test 
Professional (QTP). 
As Vb Script is Lightweight language, there is no need to compile the program, during execution they 
got interpreted and run. No .exe file got generated. 
Script engines like Wscript.exe & Cscript.exe interpret VBScript file in Windows GUI environment 
using Windows script Host. WSH is the system module that transforms a VBScript file into a Windows 
executable file. Wscript.exe is used to display output and receive input in Windows GUI format such as 
dialog and input boxes. Cscript.exe is used in a command-line environment. 
VBScript Variable 
In VBScript all variables are of the type variant that can store any type of value. 
It supports int, long, double, String, Boolean ,date datatypes. A variant behaves as a number when it is 
used in a numeric context and as a string when used in a string context. 
Variables can be declared using the following statements that determines the scope of the variable. 
The scope of the variable plays a crucial role when used within a procedure or classes. 
ñDim --Variables declared with Dim at the script level are available to all procedures within the script. 
At the procedure level, variables are available only within the procedure. 
ñPublic Variables declared using "Public" Keyword are available to all the procedures across all the 
associated scripts. 
ñPrivate --Variables that are declared as "Private" have scope only within that script in which they are 
declared. 
VB Script String Functions: 
Len Function : Returns the number of characters in a string 
Example: 
Str="Welcome to the QTP Learning Blog" 
Msgbox Len(Str) 
' Output --> 32 
Msgbox Len("Mindfire Solutions") 
' Output--> 18
LCase Function : Returns a string that has been converted to lowercase. 
Example: 
Str="Welcome to the QTP Learning Blog" 
Msgbox LCase(Str) 
' Output --> welcome to the qtp learning blog 
Msgbox LCase("Mindfire Solutions") 
' Output--> mindfire solutions 
UCase Function : Returns a string that has been converted to uppercase. 
Str="Welcome to the QTP Learning Blog" 
Msgbox UCase(Str) 
' Output --> WELCOME TO QTP LEARNING BLOG 
Msgbox UCase("Mindfire Solutions") 
' Output--> MINDFIRE SOLUTIONS 
Left Function :Returns a specified number of characters from the left side of a string. 
Str="Welcome to the QTP Learning Blog" 
Msgbox LEFT(Str,7) 
' Output --> Welcome 
Msgbox LEFT("Mindfire Solutions",2) 
' Output--> Mi 
second parameter is Numeric expression indicating how many characters to return. If 0, a zero-length 
string("") is returned. If greater than or equal to the number of characters in string, the entire string is 
returned. 
Msgbox LEFT(Str,40) 
' Output --> WELCOME TO QTP LEARNING BLOG
Msgbox LEFT("Mindfire Solutions",0) O/P—blank msgbox 
Right Function : Returns a specified number of characters from the right side of a string. 
Str="Welcome to the QTP Learning Blog" 
Msgbox Right(Str,7) 
' Output --> ng Blog 
Msgbox Right("Mindfire Solutions",2) 
' Output--> ns 
second parameter is Numeric expression indicating how many characters to return. If 0, a zero-length 
string("") is returned. If greater than or equal to the number of characters in string, the entire string is 
returned. 
Msgbox Right(Str,40) 
' Output --> WELCOME TO QTP LEARNING BLOG 
Msgbox Right("Mindfire Solutions",0) O/P—blank msgbox 
Mid Function : Returns a specified number of characters from a string. 
Str="Welcome to the QTP Learning Blog" 
Msgbox Mid(Str,3,4) 
' Output --> lcom 
Msgbox Mid("Mindfire Solutions",2,5) 
' Output--> indfi 
Msgbox Mid("Mindfire Solutions",2) 
' Output--> indfire Solutions 
Second parameter, in string at which the part to be taken begins. If start is greater than the number 
of characters in string, Mid returns a zero-length string ("") which is blank. 
Third parameter, Number of characters to return. If omitted , all characters from the start position to 
the end of the string are returned. 
Replace Function : It Returns a string in which a specified substring has been replaced with another
substring a specified number of times. 
Str="Welcome to the QTP Learning Blog" 
print Replace(Str, "to","into") 
'Output --> Welcome into the QTP Learning Blog 
Print Replace("Mindfire Solutions","Solutions","Org") 
'Output --> Mindfire Org 
Print Replace("Quick Test ProfeSsional","s","x",5,3,0) 
'Output --> k Text ProfeSxional 
Print Replace("Quick Test ProfeSsional","s","x",5,3,1) 
'Output --> k Text Profexxional 
Second parameter, in string is which specified substring has been replaced 
Third parameter, is the Replacement substring. 
Fourth, Fifth and Sixth parameters are optional. Fourth and fifth stands for start position and count. 
Both are used in together. Sixth is compare mode, default is 0 (binary comparison) which means case 
sensitive. If 1, then case in sensitive. 
Space Function : It Returns a string consisting of the specified number of spaces. 
Str1="Welcome" 
Str2="to the QTP" 
Str3="Learning Blog" 
Str4="By Nilanjan" 
MsgBox Str1 & Space(10) & Str2 & Space(2) &Str3 &Str4 
'Output--> Welcome to the QTP Learning BlogBy Nilanjan 
Split Function : it Returns an one-dimensional array containing a specified number of substrings. 
'Comma As Delimitter 
Str="Welcome,to,the,QTP, Learning,Blog" 
'Split
SArray=Split(Str,",",-1) 
For i= 0 to UBound(SArray) 
Msgbox SArray(i) 
Next 
SArray here holds the returned array 
StrComp Function : It Returns a value indicating the result of a string comparison. 
Str="Welcome into the QTP Learning Blog" 
Str1 = "QTP" 
Str2 = "qtp" 
Msgbox StrComp(Str1, Str2, 1) 
'Output--> Returns 0 , which means Str1 is equal to Str2 for textual comparison 
Msgbox StrComp(Str1, Str2, 0) 
'Output--> Returns -1 , which means Str2 is greater than Str1 for Binary comparison 
Msgbox StrComp("Nilanjana", "Nilanjan", 0) 
'Output--> Returns 1 
StrReverse Function : It Returns a string in which the character order of a specified string is reversed. 
Str="Welcome to the QTP Learning Blog” 
msgbox StrReverse(Str) 
'Output-->gplB gninraeL PTQ eht ot emocleW 
Msgbox StrReverse("Mindfire Solutions") 
'Output-->snoituloS erifdniM 
Trim Functions : t Returns a copy of a string without leading and trailing spaces 
LTrim : It Returns a copy of a string without leading spaces 
Rtrim: It Returns a copy of a string without trailing spaces 
Example:
'LTrim 
Msgbox Ltrim(" Welcome to the QTP Learning Blog ") 
'Output-->"Welcome to the QTP Learning Blog “ 
Example: 
'RTrim 
Msgbox Rtrim(" Welcome to the QTP Learning Blog ") 
'Output--> " Welcome to the QTP Learning Blog " 
Example: 
'Trim 
Msgbox Trim(" Welcome to the QTP Learning Blog ") 
'Output-->"Welcome to the QTP Learning Blog " 
InStr Function : It Returns the position of the first occurrence of one string within another string. 
Str="Welcome to the QTP Learning Blog.qtp is a testing tool" 
msgbox Instr(1, Str, "QTP", 1) 
'Output--> 16 , which means it found the string in 16th position for textual comparison 
msgbox Instr(6, Str, "qtp", 0) 
'Output--> 34 , which means it found the string in 34th position for binary comparison. 
Search started from 6th character. 
msgbox Instr(6, Str, "Ftp", 0) 
'Output--> 0 , which means it did not found the string after the 6th position 
for binary comparison
Learn VbScript -String Functions

More Related Content

PPTX
PDF
Vbscript
PPTX
VB Script
PPT
QTP VB Script Trainings
PPT
VB Script Overview
PPTX
Basic vbscript for qtp
PPT
Qtp - Introduction to fundamentals of vbscript
PDF
Vb script tutorial for qtp[1]
Vbscript
VB Script
QTP VB Script Trainings
VB Script Overview
Basic vbscript for qtp
Qtp - Introduction to fundamentals of vbscript
Vb script tutorial for qtp[1]

What's hot (20)

PDF
7400354 vbscript-in-qtp
PPT
Vb script
PDF
PPTX
Operators used in vb.net
DOC
Conditional statements in vb script
PPTX
TypeScript, Now.
PPTX
Vb script final pari
PPT
Javascript sivasoft
PPTX
Introduction to TypeScript
PPTX
Javascript conditional statements
DOCX
Vb script tutorial
PPTX
Looping statements
PPTX
JavaScript Conditional Statements
PDF
CONST-- once initialised, no one can change it
PPTX
Javascripts hidden treasures BY - https://geekyants.com/
PPTX
Spf Chapter5 Conditional Logics
PPTX
C# Loops
PPTX
Spf Chapter4 Variables
PPTX
Switch case and looping jam
DOC
Advanced+qtp+open+order
7400354 vbscript-in-qtp
Vb script
Operators used in vb.net
Conditional statements in vb script
TypeScript, Now.
Vb script final pari
Javascript sivasoft
Introduction to TypeScript
Javascript conditional statements
Vb script tutorial
Looping statements
JavaScript Conditional Statements
CONST-- once initialised, no one can change it
Javascripts hidden treasures BY - https://geekyants.com/
Spf Chapter5 Conditional Logics
C# Loops
Spf Chapter4 Variables
Switch case and looping jam
Advanced+qtp+open+order
Ad

Viewers also liked (7)

PPTX
Qtp vb scripting
PDF
Vb script reference
DOC
vbscripting
PDF
VBScript Tutorial
PPT
vb script
PPT
Intorudction into VBScript
PPT
VBscript
Qtp vb scripting
Vb script reference
vbscripting
VBScript Tutorial
vb script
Intorudction into VBScript
VBscript
Ad

Similar to Learn VbScript -String Functions (20)

PDF
stringsinpython-181122100212.pdf
PDF
Strings in python
PPTX
Strings cprogramminglanguagedsasheet.pptx
DOCX
Functions.docx
PPTX
13. Java text processing
PPTX
Best C++ Programming Homework Help
PDF
Python Strings Methods
PDF
Unit 1-Part-5-Functions and Set Operations.pdf
PPTX
Python Training in Bangalore | Python Introduction Session | Learnbay
PPTX
Javascript
PDF
Java Version(v5 -v23) Features with sample code snippet
PDF
Runtime Bytecode Transformation for Smalltalk
PDF
The Ring programming language version 1.3 book - Part 26 of 88
PPT
Implementation of 'go-like' language constructions in scala [english version]
PPTX
POEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjk
PDF
Runtime Bytecode Transformation for Smalltalk
PPTX
Advanced procedures in assembly language Full chapter ppt
PDF
strings11.pdf
PDF
A "Do-It-Yourself" Specification Language with BeepBeep 3 (Talk @ Dagstuhl 2017)
PDF
00012.PYTHON - STRING MANIPULATION SLIDES
stringsinpython-181122100212.pdf
Strings in python
Strings cprogramminglanguagedsasheet.pptx
Functions.docx
13. Java text processing
Best C++ Programming Homework Help
Python Strings Methods
Unit 1-Part-5-Functions and Set Operations.pdf
Python Training in Bangalore | Python Introduction Session | Learnbay
Javascript
Java Version(v5 -v23) Features with sample code snippet
Runtime Bytecode Transformation for Smalltalk
The Ring programming language version 1.3 book - Part 26 of 88
Implementation of 'go-like' language constructions in scala [english version]
POEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjk
Runtime Bytecode Transformation for Smalltalk
Advanced procedures in assembly language Full chapter ppt
strings11.pdf
A "Do-It-Yourself" Specification Language with BeepBeep 3 (Talk @ Dagstuhl 2017)
00012.PYTHON - STRING MANIPULATION SLIDES

Recently uploaded (20)

PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
master seminar digital applications in india
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Cell Types and Its function , kingdom of life
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
GDM (1) (1).pptx small presentation for students
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Lesson notes of climatology university.
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Computing-Curriculum for Schools in Ghana
PDF
Classroom Observation Tools for Teachers
PDF
RMMM.pdf make it easy to upload and study
STATICS OF THE RIGID BODIES Hibbelers.pdf
Microbial disease of the cardiovascular and lymphatic systems
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
master seminar digital applications in india
Complications of Minimal Access Surgery at WLH
Final Presentation General Medicine 03-08-2024.pptx
Cell Types and Its function , kingdom of life
102 student loan defaulters named and shamed – Is someone you know on the list?
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
human mycosis Human fungal infections are called human mycosis..pptx
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
GDM (1) (1).pptx small presentation for students
VCE English Exam - Section C Student Revision Booklet
Lesson notes of climatology university.
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Computing-Curriculum for Schools in Ghana
Classroom Observation Tools for Teachers
RMMM.pdf make it easy to upload and study

Learn VbScript -String Functions

  • 1. VBScript in QTP Microsoft VBScript (Visual Basic Script) is a general-purpose, lightweight , scripting language developed by Microsoft which is modeled on Visual Basic. VBScript is the main scripting language for Quick Test Professional (QTP). As Vb Script is Lightweight language, there is no need to compile the program, during execution they got interpreted and run. No .exe file got generated. Script engines like Wscript.exe & Cscript.exe interpret VBScript file in Windows GUI environment using Windows script Host. WSH is the system module that transforms a VBScript file into a Windows executable file. Wscript.exe is used to display output and receive input in Windows GUI format such as dialog and input boxes. Cscript.exe is used in a command-line environment. VBScript Variable In VBScript all variables are of the type variant that can store any type of value. It supports int, long, double, String, Boolean ,date datatypes. A variant behaves as a number when it is used in a numeric context and as a string when used in a string context. Variables can be declared using the following statements that determines the scope of the variable. The scope of the variable plays a crucial role when used within a procedure or classes. ñDim --Variables declared with Dim at the script level are available to all procedures within the script. At the procedure level, variables are available only within the procedure. ñPublic Variables declared using "Public" Keyword are available to all the procedures across all the associated scripts. ñPrivate --Variables that are declared as "Private" have scope only within that script in which they are declared. VB Script String Functions: Len Function : Returns the number of characters in a string Example: Str="Welcome to the QTP Learning Blog" Msgbox Len(Str) ' Output --> 32 Msgbox Len("Mindfire Solutions") ' Output--> 18
  • 2. LCase Function : Returns a string that has been converted to lowercase. Example: Str="Welcome to the QTP Learning Blog" Msgbox LCase(Str) ' Output --> welcome to the qtp learning blog Msgbox LCase("Mindfire Solutions") ' Output--> mindfire solutions UCase Function : Returns a string that has been converted to uppercase. Str="Welcome to the QTP Learning Blog" Msgbox UCase(Str) ' Output --> WELCOME TO QTP LEARNING BLOG Msgbox UCase("Mindfire Solutions") ' Output--> MINDFIRE SOLUTIONS Left Function :Returns a specified number of characters from the left side of a string. Str="Welcome to the QTP Learning Blog" Msgbox LEFT(Str,7) ' Output --> Welcome Msgbox LEFT("Mindfire Solutions",2) ' Output--> Mi second parameter is Numeric expression indicating how many characters to return. If 0, a zero-length string("") is returned. If greater than or equal to the number of characters in string, the entire string is returned. Msgbox LEFT(Str,40) ' Output --> WELCOME TO QTP LEARNING BLOG
  • 3. Msgbox LEFT("Mindfire Solutions",0) O/P—blank msgbox Right Function : Returns a specified number of characters from the right side of a string. Str="Welcome to the QTP Learning Blog" Msgbox Right(Str,7) ' Output --> ng Blog Msgbox Right("Mindfire Solutions",2) ' Output--> ns second parameter is Numeric expression indicating how many characters to return. If 0, a zero-length string("") is returned. If greater than or equal to the number of characters in string, the entire string is returned. Msgbox Right(Str,40) ' Output --> WELCOME TO QTP LEARNING BLOG Msgbox Right("Mindfire Solutions",0) O/P—blank msgbox Mid Function : Returns a specified number of characters from a string. Str="Welcome to the QTP Learning Blog" Msgbox Mid(Str,3,4) ' Output --> lcom Msgbox Mid("Mindfire Solutions",2,5) ' Output--> indfi Msgbox Mid("Mindfire Solutions",2) ' Output--> indfire Solutions Second parameter, in string at which the part to be taken begins. If start is greater than the number of characters in string, Mid returns a zero-length string ("") which is blank. Third parameter, Number of characters to return. If omitted , all characters from the start position to the end of the string are returned. Replace Function : It Returns a string in which a specified substring has been replaced with another
  • 4. substring a specified number of times. Str="Welcome to the QTP Learning Blog" print Replace(Str, "to","into") 'Output --> Welcome into the QTP Learning Blog Print Replace("Mindfire Solutions","Solutions","Org") 'Output --> Mindfire Org Print Replace("Quick Test ProfeSsional","s","x",5,3,0) 'Output --> k Text ProfeSxional Print Replace("Quick Test ProfeSsional","s","x",5,3,1) 'Output --> k Text Profexxional Second parameter, in string is which specified substring has been replaced Third parameter, is the Replacement substring. Fourth, Fifth and Sixth parameters are optional. Fourth and fifth stands for start position and count. Both are used in together. Sixth is compare mode, default is 0 (binary comparison) which means case sensitive. If 1, then case in sensitive. Space Function : It Returns a string consisting of the specified number of spaces. Str1="Welcome" Str2="to the QTP" Str3="Learning Blog" Str4="By Nilanjan" MsgBox Str1 & Space(10) & Str2 & Space(2) &Str3 &Str4 'Output--> Welcome to the QTP Learning BlogBy Nilanjan Split Function : it Returns an one-dimensional array containing a specified number of substrings. 'Comma As Delimitter Str="Welcome,to,the,QTP, Learning,Blog" 'Split
  • 5. SArray=Split(Str,",",-1) For i= 0 to UBound(SArray) Msgbox SArray(i) Next SArray here holds the returned array StrComp Function : It Returns a value indicating the result of a string comparison. Str="Welcome into the QTP Learning Blog" Str1 = "QTP" Str2 = "qtp" Msgbox StrComp(Str1, Str2, 1) 'Output--> Returns 0 , which means Str1 is equal to Str2 for textual comparison Msgbox StrComp(Str1, Str2, 0) 'Output--> Returns -1 , which means Str2 is greater than Str1 for Binary comparison Msgbox StrComp("Nilanjana", "Nilanjan", 0) 'Output--> Returns 1 StrReverse Function : It Returns a string in which the character order of a specified string is reversed. Str="Welcome to the QTP Learning Blog” msgbox StrReverse(Str) 'Output-->gplB gninraeL PTQ eht ot emocleW Msgbox StrReverse("Mindfire Solutions") 'Output-->snoituloS erifdniM Trim Functions : t Returns a copy of a string without leading and trailing spaces LTrim : It Returns a copy of a string without leading spaces Rtrim: It Returns a copy of a string without trailing spaces Example:
  • 6. 'LTrim Msgbox Ltrim(" Welcome to the QTP Learning Blog ") 'Output-->"Welcome to the QTP Learning Blog “ Example: 'RTrim Msgbox Rtrim(" Welcome to the QTP Learning Blog ") 'Output--> " Welcome to the QTP Learning Blog " Example: 'Trim Msgbox Trim(" Welcome to the QTP Learning Blog ") 'Output-->"Welcome to the QTP Learning Blog " InStr Function : It Returns the position of the first occurrence of one string within another string. Str="Welcome to the QTP Learning Blog.qtp is a testing tool" msgbox Instr(1, Str, "QTP", 1) 'Output--> 16 , which means it found the string in 16th position for textual comparison msgbox Instr(6, Str, "qtp", 0) 'Output--> 34 , which means it found the string in 34th position for binary comparison. Search started from 6th character. msgbox Instr(6, Str, "Ftp", 0) 'Output--> 0 , which means it did not found the string after the 6th position for binary comparison