Datatypes in UFT – User friendly Tech help

Data types in Vbscript:-

n

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.

n

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

n

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

n

We will use the same variables to serve dual purpose.

n

‘Declaring variables

n
nDim var1, var2n

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

n

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

n

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

n

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

n

n

n

n

n

n

n

n

Addition of numbers

n

n

n

n

n

n

n

n

String concatenation

n

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

n

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.

n

Major subtypes (categories) of variant:-
n

n

Important:-

n

    n

  • We can make number behaving as strings by enclosing in “ ”
  • n

  • We can use conversion functions of vbscript to convert from one subtype to another.
  • n

  • We can use VarType function, to check the subtype of a variable
  • n

Was this article helpful?
YesNo

Similar Posts