Data Types - DOC

Document Sample
Data Types - DOC Powered By Docstoc
					                          www.gcreddy.com


                                      Visit:

     www.gcreddy.com
                       for vbscript and QTP info
--------------------------------------------------

                      VB Script Data Types

What is Data Type?

Data type is a categorization of identifying one of various types of data, such as
string, integer, double, date or Boolean etc…

Implicit & Explicit Data types:

Specifying Data types along with variable names is called Explicit declaration of Data
types.

Declaring Variables Without specifying Data types is called Implicit declaration of
variables.

VB Script Supports Implicit declaration of variables only, doesn‟t support Explicit
declaration of Data types.

VB Script Data Type:

VB script has only data type called Variant, it can hold any type of data, and based
on usage of data it considers data sub types.

Example:

Dim x

X is a Variable and it can hold any type of data (String, integer, double, date etc…)

X= “G C Reddy” ‘String type

X= 100 ‘Integer

X= 10.345 ‘Double

X=#10/10/2010# ‘Date



                              www.gcreddy.com                                           1
                             www.gcreddy.com

How to know Data sub types:

Using VarType Function we can get data sub type

VarType Function

It returns a value indicating a subtype of a Variable

Example:

'Checking Data sub types
-----------------------------
Dim x, y, z(3)
x="Gcreddy"
Msgbox VarType(x) '8 for String

x=500
Msgbox VarType(x) ' 2 for Integer

x="400"
Msgbox VarType(x) '8 for String

x=199.123
Msgbox VarType(x) '5 for double

x="199.123"
Msgbox VarType(x) '8 for string

x=#10/10/2010#
Msgbox VarType(x) '7 for date

Set x =CreateObject("Scripting.FileSystemObject")
Msgbox VarType(x) '9 for Automation Object

x=384322225
Msgbox VarType(x) ‘3 for Long integer

Msgbox VarType(z) ‘8204 for Array

Msgbox VarType(y) '0 for Empty / Uninitialized

-------------------------------------------------------------------------------------
Data sub type and descriptions:

String:

It consists of any type of characters, maximum length up to approximately 2 billion
characters.

Boolean:
It Contains either True or False (Logical Result)



                               www.gcreddy.com                                          2
                             www.gcreddy.com

Empty:

Uninitialized, Value is 0 for numeric variables or a zero-length string ("") for string
variables.

Integer:

Contains integer in the range -32,768 to 32,767

Long Integer

Contains integer in the range -2,147,483,648 to 2,147,483,647

Double:
Contains a double-precision, floating-point number in the range -
1.79769313486232E308 to -4.94065645841247E-324 for negative values;
4.94065645841247E-324 to 1.79769313486232E308 for positive values.

Date:

Contains a number that represents a date between January 1, 100 to December 31,
9999

Object:

Contains an object

Error:

Contains an error number

Null:

Contains no valid data

Etc…
------------------------------------------------------------------------------------


'Converting the Data from one type to another
-----------------------------------------------
We use Conversion Functions to convert the data from one type to another.

Whenever we read data using input devices, or from files, or from Databases or from
Application objects then VB Script considers the data as string type data, we need to
convert the data in order to perform operations.

Dim x, y, Tickets, Price
'Read from Input Devices
x=InputBox("Enter a Value")
Msgbox VarType(x) '8 for String
x=Cint(x)


                               www.gcreddy.com                                            3
                             www.gcreddy.com
Msgbox VarType(x) '2 for Integer

y=InputBox("Enter a Value")
Msgbox VarType(y) '8 for String
y=Cdbl(y)
Msgbox VarType(y) '5 for double

'Read from Application Objects

Tickets = Window("Flight Reservation").WinEdit("Tickets:").GetVisibleText()
Msgbox VarType(Tickets)'8
Tickets=Cint(Tickets)
Msgbox VarType(Tickets) '2

Price = Window("Flight Reservation").WinEdit("Price:").GetVisibleText()
Msgbox VarType(Price) '8
Price=Cdbl(Price)
Msgbox VarType(Price) '5

----------------------------------------------------------------------
Example: 2
Dim a, b, c

a=”100”
Msgbox VarType(a) „ 8 for String

a=Cint(a)
Msgbox VarType(a) „2 for Integer

b=”100.345”
Msgbox VarType(b) „ 8 for String

b=Cdbl(b)
Msgbox VarType(b) „5 for Double

c=”Hyderabad”
Msgbox VarType(c) „8 for String

c=Cint(c)
Msgbox VarType(c) „Mismatch (Error)

Note: we can’t convert alphabets as integer or double type data

Thanks
G C Reddy




                               www.gcreddy.com                                4

				
DOCUMENT INFO
Shared By:
Categories:
Stats:
views:49
posted:9/6/2011
language:English
pages:4
Description: VB Script data types for qtp testers.