Monday, February 1, 2010

Add Space Or Remove space on Variable

Remove the Space from the Variable

Dim MyValue,MyFunction,MyReturn
MyValue = "Vinodh Kumar"
MyFunction = split(MyValue, " " , -1,1)
MyReturn =MyFunction(0)& space(0) & MyFunction(1)
msgbox MyReturn

Add some Space from the Variable

Dim MyString, MyArray, MyReturn
MyString = "MDVDebuggerXForXVinodh"
MyArray = Split(MyString, "X", -1, 1)
msgbox myarray(0)
MyReturn = MyArray(0) & " " & MyArray(1)
MyReturn = MyReturn & " " & MyArray(2)
MsgBox MyReturn

QTP - Excel Part1

Write a program to Import an excel file to a Data table

datatable.Import("C:\vbsample.xls")

Write a program to Read data from first parameter of Global sheet

a = Datatable.Value("UserName",Global)
Dialog("text:=Login").WinEdit("attached text:=Agent Name:").Set a

Run all the Rows in Global sheet or Local Sheet using mercury Login Apps

datatable.Import("C:\vbsample.xls")
DataTable.ImportSheet "C:\vbsample.xls",1,1
c = datatable.GetCurrentRow
d = datatable.GetRowCount

For i = c to d -1 step 1
systemUtil.Run("C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe")

a = Datatable.Value("UserName",Global)
Dialog("text:=Login").WinEdit("attached text:=Agent Name:").Set a

b = Datatable.Value("Password",global)

Dialog("text:=Login").WinEdit("attached text:=Password:").Set b
Dialog("text:=Login").Winbutton("text:=OK").click
window("Flight Reservation").Close
datatable.SetNextRow
Next

Write a program to Read data from all sheets and all parameters of the excel file

Set ExlApp = CreateObject("Excel.Application")
Set ExlB = ExlApp.Workbooks.open("C:\vbsample.xls")
Set Exlbs = ExlApp.worksheets(1)
colcount = Exlbs.usedrange.columns.count
Rowcount =Exlbs.usedrange.rows.count
'Msgbox colcount
'Msgbox rowcount
For i =2 to rowcount -1 'step 1
colval = exlbs.cells(i,1)
systemUtil.Run("C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe")
Dialog("text:=Login").WinEdit("attached text:=Agent Name:").Set colval
For j=2 to colcount -1 'step 1
rowval =exlbs.cells(2,j)
'msgbox rowval
Dialog("text:=Login").WinEdit("attached text:=Password:").Set rowval
Dialog("text:=Login").Winbutton("text:=OK").click
window("Flight Reservation").Close
Next
'If (colcount = rowcount)Then
' For j=2 to colcount -1 step 1
' rowval = exlbs.cells(j,1)
' msgbox rowval
'Next
'End If
'Datatable.SetNextRow
Next
set ExlAppl=nothing
Set Exlb = nothing
Set Exlbs= nothing