Over a million developers have joined DZone.

Testing in HP QTP with VB Script

DZone's Guide to

Testing in HP QTP with VB Script

VB Script is used for HP QTP scripting in order to create Test Scripts.

· DevOps Zone ·
Free Resource

Is the concept of adopting a continuous everything model a daunting task for your fast moving business? Read this whitepaper to break down and understand one of the key pillars of this model in Continuous Governance: The Guardrails for Continuous Everything.

VB Script is used for HP QTP scripting in order to create Test Scripts. VB Script is a Microsoft language where using for .Net development for Web applications. VB Script is a lightweight language, easy to understand, easy to learn and very easy to prepare QTP Test scripts for QTP framework.

Purpose of VB Script in QTP

1.VB Script coding used in hp QTP Test scripting.

2.VB Script is a Microsoft language.

3.Licensed by a many companies and using for programming Language.

VB Script Data Types

VB Script has only one Data type i.e Variant which is used in vb script.Variant is a type of data type that having different information.Variant used as a Null pointer,Boolean,Byte,Storage purpose..etc

Variable is used as a Array type to store information.We can store different type of data into this variable.Vb Script variable should not exceed 255 characters and must be unique.


VB Script has different variable to declare values or assigned types using Dim,Public,Private statements.

  • Dim - Used for all functions with in the script like global declarations

  • Public - Used for all functions or procedures for all the scripts

  • Private - Used for only for which scripts it has declared.


'Global Variable Declarations

Dim k,l,m

'Assign value to K

K = Inputype("Please Enter k value")

'Assign value to l

l= InputType("Please Enter l value")

'Addition of two integers


'Display Addition value m


Option Explicit is also a variable to declare variables,if Option Explicit used you should declare variables in Test scripts for all the variables.If used Option Explicit it will provide details if variables are not declare under Dim or Public or Private  statements.

VB Script Arrays

Array is a type of storage container which is used to store  the particular fixed size of  values of a single type.The length for array is established at the time of array is created.Array is starts with number 0 for example below.


a[3] means


a[0] = 1

a[1]= 2

a[2] = 3

a[3] = 4

Two Types of Arrays

1.Static Array

2.Dynamic Array

Static Array:

In this Static Array we can mention size of the array while declaring the array. For Example

Dim Value[3]

Value[0] = 1

Value[1] = 2

Value[2] = 3

Value[3] = 4

Dynamic Array

In this type of Array we can change the array size at the type of Test script and we can resize the array size in Dynamic Array.


Dim a()

Suppose if we want to resize the specified array we can use ReDim statement to resize the dynamic array size.

ReDim a(5)

Are you looking for greater insight into your software development value stream? Check out this whitepaper: DevOps Performance: The Importance of Measuring Throughput and Stability to see how CloudBees DevOptics can give you the visibility to improve your continuous delivery process.

software testing ,automation testing ,vbscript ,test automation ,programming languages ,web dev ,devops

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}