TESTEVERYTHING

Showing posts with label Date. Show all posts
Showing posts with label Date. Show all posts

Monday, 5 September 2011

VB Script Data Types


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

 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)

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)
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

Source...
G C Reddy

Wednesday, 22 June 2011

Validation of Sorting in WEBTABLE / QTP

Hi All,
Some time in application we have to verify the sorting functionality.In Web table for each column we need to click and check is it working fine or not. Here i am giving an example of sorting the date column. but it will verify in ascending order.

logic for this:
  1. Click on Date column which sort the date in ascending order.
  2. Get first row and second row date value form Date column
  3. Check first row date should be less than or equal to second row date.
  4. Get second row and third row date value.
  5. Check second row date should be less than or equal to third row date value.
  6. Same way check until end of row using For Loop.
  7. In the case if you got false result while comparison two row you need to break the for loop and show  the   fail result......

set TableObject = Browser(“XYZ”).Page(“WXY”).WebTable(“MNP”)
TableRowcount  = Browser(“XYZ”).Page(“WXY”).WebTable(“MNP”).RowCount

For i =1 to TableRowcount -1
 dtmCurrRow  = TableObject.GetcellData(i,<DateColumn>)

 dtmNextRow  =  = TableObject.GetcellData(i+1,<DateColumn>)
      If  NOT cdate(dtmCurrRow) <=  cdate(dtmNextRow) Then
              Flage = 1
              Exit For
      End If
End
If  Flage <> 1 than
  msgbox  "Pass"
Else
  msgbox  "Fail"
End if

Translate







Tweet