Datatypes in UFT

Data types in Vbscript:-

It has only one dataype called as Variant ,as the name indicates its data type changes as per  the context in which it is used.Idea is vbscript is loosely typed language, so you are using variables without declaring, the type of data that will be stored in the variable.

Scenario: – we need to add to numbers and concatenate two strings.

Solution: – we require 2 variables of integer type and 2 of string type .

We will use the same variables to serve dual purpose.

‘Declaring variables
Dim var1, var2

‘Assigning the integer values 
var1 = 1 : var2 = 2

Msgbox (“Result is addition: “&var1+var2)

‘Reassigning the values with strings
var1 = “UFT” : var2 = “Help”

msgbox (“Reuslt is concatenation: “&var1+var2)

Addition of numbers

String concatenation

Thus everything is context dependent, above variables behaved as integer, when an integer values were assigned and as string datatype on assigning string values.

In nutshell, we can just put the kind of data we want in a Variant, and the Variant behaves in a way that is most appropriate for the data it contains.

Major subtypes (categories) of variant:-

SubTypes in qtp

  • We can make number behaving as strings by enclosing in “ ”
  • We can use conversion functions of vbscript to convert from one subtype to another.
  • We can use VarType function, to check the subtype of a variable

Leave a Reply

Your email address will not be published. Required fields are marked *