Friday, February 4, 2011

Creating dictionary using Vbscript


Dim vKey
Dim sItem, sMsg
Dim oDict

'--- Creating a dictionary object
Set oDict = CreateObject("Scripting.Dictionary")

'--- Adding items to dictionary
oDict.Add "One", "Engine"
oDict.Add "Two", "Wheel"
oDict.Add "Three", "Tire"
oDict.Add "Four", "Spanner"

'--- Looping the Collection
For Each vKey In oDict
sItem = oDict.Item(vKey)
'sMsg = sMsg & sItem & vbCrLf
Next

'WScript.Echo (oDict.Count)
'oDict.Item("one") = "temp"
'WScript.Echo sMsg

'wscript.Echo (odict.item(one))
oDict.Key("One") = "nine"
'oDict.Item("nine") = "nine"
oDict.Add "Ten", "ten"

For Each vKey In oDict
sItem = oDict.Item(vKey)
sMsg = sMsg & sItem & " - " &vKey & vbCrLf
Next

WScript.Echo sMsg

WScript.Echo "===============Again============="

WScript.Echo (oDict.Exists ("One"))
WScript.Echo (oDict.Exists ("nine"))
WScript.Echo (oDict.Exists ("Ten"))

'WScript.Echo (odict.item(One))1
'WScript.Echo (odict.item(nine))
'WScript.Echo (odict.item(Ten))

For Each vKey In oDict
sItem = oDict.Item(vKey)
WScript.Echo (sItem & " - " & vKey)
Next

If oDict.Exists("One") Then
WScript.Echo "heello"
End If


If oDict.Exists("nine") Then
WScript.Echo "heello"
End If

Dim temp()
Dim count, counter
count = oDict.Count
WScript.Echo (count)

WScript.Echo
ReDim temp(count)
counter = 0
For Each key In oDict
temp(counter) = key
' WScript.Echo key & " - " & counter
' WScript.Echo temp(counter)
counter = counter+1
Next


'WScript.Echo ("oDict.Keys")

Vbscript Function Related to Date

dtm1="18-Feb-10"
dtm2="19-Aug-10"

'To Get difference between two date
WScript.Echo "Difference between " & dtm1 & " and " & dtm2

'To Get month difference
intMonthsDifferent=DateDiff("m", dtm1, dtm2)
WScript.Echo "In month: " & intMonthsDifferent

'To Get date difference
intDateDifferent=DateDiff("d", dtm1, dtm2)
WScript.Echo "In date: " & intDateDifferent

If intMonthsDifferent > 0 Then
WScript.Echo "postive"
Else
WScript.Echo "negative"
End If

'Difference In date with difference format Another example

dtm1="18/02/1999"
dtm2="18/03/1998"

WScript.Echo "Difference between " & dtm1 & " and " & dtm2
intMonthsDifferent=DateDiff("m", dtm1, dtm2)
WScript.Echo "In month: " & intMonthsDifferent
intDateDifferent=DateDiff("d", dtm1, dtm2)
WScript.Echo "In date: " & intDateDifferent

If intMonthsDifferent > 0 Then
WScript.Echo "postive"
Else
WScript.Echo "negative"
End If

WScript.Echo "-----------------------------------------------"
WScript.Echo "Function To Get different value of current Date"
WScript.Echo "-----------------------------------------------"

WScript.Echo "Current Date:- " &(Date ())
WScript.Echo "Current Time:- " &(Time ())
WScript.Echo "Current Time:- " & TimeValue (Time)
WScript.Echo "Current Time and date:- " & Now ()
WScript.Echo "Hours:- " & Hour (Time)
WScript.Echo "Month:- " & Month (Date)
WScript.Echo "Second:- " & Second (time)
WScript.Echo "Total Seconds:- " & Timer ()
WScript.Echo "Time with User's Argument:- " & TimeSerial (13,56,8)
WScript.Echo Weekday (Date)
WScript.Echo "Day's name as per index:- " & WeekdayName(Weekday(1))
WScript.Echo "Day's name as per index:- " & WeekdayName(Weekday(2))
WScript.Echo "Day's name as per index:- " & WeekdayName(Weekday(3))
WScript.Echo "Day's name as per index:- " & WeekdayName(Weekday(8))
WScript.Echo "Month's name as per index:- " & MonthName (1)
WScript.Echo "Month's name as per index:- " & MonthName (12)

Data Type Validation in Vbscript

Dim temp
WScript.Echo (VarType (temp))
WScript.Echo (TypeName (temp))
WScript.Echo

temp = 3
WScript.Echo (VarType (temp))
WScript.Echo (TypeName (temp))
WScript.Echo

temp = 3111111
WScript.Echo (VarType (temp))
WScript.Echo (TypeName (temp))
WScript.Echo

temp = "afsda"
WScript.Echo (VarType (temp))
WScript.Echo (TypeName (temp))
WScript.Echo

ReDim temp(6)
WScript.Echo (TypeName (temp))
WScript.Echo

temp(0) = 1
temp(1) = 1
WScript.Echo (VarType (temp))

WScript.Echo (vbSunday)
WScript.Echo (TypeName (temp))

Playing with array

WScript.echo "-------------------------------------------------------"
WScript.echo "Playing with array"
wscript.echo "-------------------------------------------------------"

Dim arrArray
Dim i
Dim sTmp
arrArray = Array(81,117,105,99,107,84,101,115,116,45,80,114,111)

'--- Checking if variable is an array.
If IsArray(arrArray) Then
For i = LBound(arrArray) To UBound(arrArray)
WScript.Echo (arrArray(i))
arrArray(i) = Chr(arrArray(i))
WScript.Echo (arrArray(i))
Next
End If

If IsArray(arrArray) Then
sTmp = Join(arrArray, vbNullString)
MsgBox sTmp
MsgBox vbNullString
MsgBox vbNull
End If

Erase arrArray
MsgBox vbArray
MsgBox vbByte

WScript.echo "-------------------------------------------------------"
WScript.echo "Split to make array n filtering"
wscript.echo "-------------------------------------------------------"


a=Split("Sunday Monday Tuesday WEDNES DAY T h urs dayF r iday Satu r day"," ",-1,1)
a=Split("Sunday Monday Tuesday WEDNES DAY T h urs dayF r iday Satu r day")
for each x in a
WScript.Echo(x)
Next

WScript.Echo
WScript.Echo "Filter Function"
WScript.Echo


WScript.Echo
WScript.Echo "True Function"
WScript.Echo

a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
b=Filter(a,"S",True,1)
for each x in b
WScript.Echo (x)
Next

WScript.Echo
WScript.Echo "True Function"
WScript.Echo

a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
b=Filter(a,"S",True,0)
for each x in b
WScript.Echo (x)
next

WScript.Echo "True Function"

a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
b=Filter(a,"S",True)
for each x in b
WScript.Echo (x)
next



WScript.Echo
WScript.Echo "False"
WScript.Echo


a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
b=Filter(a,"S",False,1)
for each x in b
WScript.Echo (x)
next

WScript.Echo
WScript.Echo "False"
WScript.Echo


a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
b=Filter(a,"S",False,0)
for each x in b
WScript.Echo (x)
next

Monday, July 26, 2010

Script conversion from Winrunner to QTP

 
Tools available to convert WR script to QTP are as follow

1.       Win Quick    (WinQuick is the only HP validated.)
2.       QTP Genie
3.       Test House
4.       Zapit
5.       Interoperate

Note:
·         All tools are licensed version  (Need to confirm for Win Quick )
·         100 % automated conversion is not possible. There would be approx 20% of manual conversion. (Ultimately we have to go through the whole code)
 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | JCpenney Printable Coupons