This is a Sample code for :
Creating a txt file, write data into that file n read data from that file.
code:
Dim fso, MyFile,ts,op,MyFile1
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile= fso.CreateTextFile("C:\text.txt", True)
MyFile.WriteLine("Last_Name" & " | " & "First_Name" & " | " & "Result") & " " & NewLine
MyFile.WriteLine("---------------------------------") & " " & NewLine
RowCnt=DataTable.GetSheet ("Action1").GetRowCount
For i=1 to RowCnt
DataTable.SetCurrentRow (i)
If DataTable.Value("Result",dtLocalSheet)="FAIL" Then
MyFile.WriteLine (DataTable.Value("Last_Name",dtLocalSheet) &" | " & DataTable.Value("First_Name",dtLocalSheet) &" | " & DataTable.Value("Result",dtLocalSheet)) & " "
MyFile.WriteLine()
end if
Next
MyFile.Close
Set f = fso.GetFile("C:\text.txt")
Set ts = f.OpenAsTextStream(1,-2)
Set MyFile1= fso.CreateTextFile("C:\text1.txt", True)
Do While Not ts.AtEndOfStream
op = op & ts.ReadLine
Loop
MyFile1.WriteLine(op)
ts.Close
MyFile1.close
Showing posts with label qtp excel. Show all posts
Showing posts with label qtp excel. Show all posts
Monday, November 7, 2011
Creating Objects
Creates a new, empty description object in which you can add collection of properties and values in order to specify the description object in place of a test object name in a step.
Syntax
set PropertiesColl = Description.Create
Example
1. set EditDesc = Description.Create()
EditDesc("Name").Value = "userName"
EditDesc("Index").Value = "0"
Browser("Welcome: Mercury").Page("Welcome: Mercury").WebEdit(EditDesc).Set "MyName"
2. 'Define User ID field object
Set oUserID = Description.Create()
oUserID("Class Name").Value = "WebEdit"
oUserID("name").Value = "j_username"
Syntax
set PropertiesColl = Description.Create
Example
1. set EditDesc = Description.Create()
EditDesc("Name").Value = "userName"
EditDesc("Index").Value = "0"
Browser("Welcome: Mercury").Page("Welcome: Mercury").WebEdit(EditDesc).Set "MyName"
2. 'Define User ID field object
Set oUserID = Description.Create()
oUserID("Class Name").Value = "WebEdit"
oUserID("name").Value = "j_username"
Wednesday, October 12, 2011
Compare values of 2 Excel sheets cell by cell
This code will open two excel sheet and compare values of each sheet cell by cell, if any changes there in cells , it will highlight the cells in red color in the first sheet.
Set objExcel = CreateObject(“Excel.Application”)
objExcel.Visible = True
Set objWorkbook1= objExcel.Workbooks.Open(“C:Documents andSettingsmohan.kakarlaDesktopDocs1.xls”)
Set objWorkbook2= objExcel.Workbooks.Open(“C:Documents and
Settingsmohan.kakarlaDesktopDocs2.xls”)
Set objWorksheet1= objWorkbook1.Worksheets(1)
Set objWorksheet2= objWorkbook2.Worksheets(1)
For Each cell In objWorksheet1.UsedRange
If cell.Value <> objWorksheet2.Range(cell.Address).Value Then
cell.Interior.ColorIndex = 3′Highlights in red color if any changes in cells
Else
cell.Interior.ColorIndex = 0
End If
Next
set objExcel=nothing
Source : MDSN
Set objExcel = CreateObject(“Excel.Application”)
objExcel.Visible = True
Set objWorkbook1= objExcel.Workbooks.Open(“C:Documents andSettingsmohan.kakarlaDesktopDocs1.xls”)
Set objWorkbook2= objExcel.Workbooks.Open(“C:Documents and
Settingsmohan.kakarlaDesktopDocs2.xls”)
Set objWorksheet1= objWorkbook1.Worksheets(1)
Set objWorksheet2= objWorkbook2.Worksheets(1)
For Each cell In objWorksheet1.UsedRange
If cell.Value <> objWorksheet2.Range(cell.Address).Value Then
cell.Interior.ColorIndex = 3′Highlights in red color if any changes in cells
Else
cell.Interior.ColorIndex = 0
End If
Next
set objExcel=nothing
Source : MDSN
Subscribe to:
Posts (Atom)