Write script to open notepad file , read the data and display it on the screen using QTP script.

Showing Answers 1 - 28 of 28 Answers

KodumuruRamesh

  • Nov 9th, 2006
 

Hi

   yes,we can get this by following this script.

Example:

 First create a notepad write the data & save it as ramesh & open another notepad (i.e blank) & save this as ramesh1.

Script:

SystemUtil.Run "c:Document and settingDesktopramesh.txt"

a=Window("Notepad").WinEditor("Edit").GetVisibleTest

Msgbox a      'to display the data in the message box

SystemUtil.Run "c:Document and settingDesktopramesh1.txt"

Window("Notepad").Type a   'to write or display the data in another notepad

kodumururamesh@yahoo.co.in

 

  Was this answer useful?  Yes

RAJAGOPAL REDDY

  • Dec 14th, 2006
 

Hi,

 

You can use file system objects and syntaxes to read/write/save/open text files; please see the following code.

dim filesys, demofolder, filetxt

Set filesys = CreateObject("Scripting.FileSystemObject")

'If already folder is there grt the folder

Set demofolder = filesys.GetFolder("c:INET")

'Other wise create folder

Set demofolder = filesys.CreateFolder("c:REDDY")

Set filetxt = demofolder.CreateTextFile("somefile.txt", True)

filetxt.WriteLine("Your text goes here.")

filetxt.Close

Thanks-RAJAGOPAL REDDY Email: Reddy_rajagopal@yahoo.co.in

 

  Was this answer useful?  Yes

hi Ramesh

window("Notepad").WinEditor doesnt work ..it says there is no function or procedure called wineditor..

a=Window("Notepad").WinEditor("Edit").GetVisibleTest

  Was this answer useful?  Yes

Jeevan

  • Dec 27th, 2006
 

Hi...

Execute this

Const ForReading=1
Set t1=createObject("Scripting.FileSystemObject")
Set t2=t1.openTextFile("c:test.txt",ForReading)
Do Until t2.AtEndOfStream
strNextLine=t2.ReadAll
MsgBox strNextLine
Loop

  Was this answer useful?  Yes

appugadu

  • Jun 27th, 2007
 

Can any body post the QTP code to accomplish the following:
1. Have data in a.xls file that has 12 columns
2. Would like to get values from column 8 th 11 th and write it to b.xls file on columns 4 and 5th.

Would apprecite your help.
Thanks

  Was this answer useful?  Yes

patsnil

  • Mar 16th, 2011
 

-------------------------------------------------------------------------------------------------------------
'1. Have data in a.xls file that has 12 columns
'2. Would like to get values from column 8 th 11 th and write it to b.xls file on columns 4 and 5th.
'------------------------------------------------------------------------------------------------------------

Dim objExcel
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set ObjExcelFile1 = objExcel.Workbooks.Open("D:ABCa.xls")
Set ObjExcelSheet1 = ObjExcelFile1.Sheets("Sheet1")
Set ObjExcelFile2 = objExcel.Workbooks.Open("D:ABCb.xls")
Set ObjExcelSheet2 = ObjExcelFile2.Sheets("Sheet1")
For i = 1 to ObjExcelSheet1.UsedRange.Rows.Count
 strValue = ObjExcelSheet1.Cells(i,8)
 ObjExcelSheet2.Cells(i,4) = strValue
 strValue1 = ObjExcelSheet1.Cells(i,11)
 ObjExcelSheet2.Cells(i,5) = strValue1
Next
ObjExcelFile2.Save
ObjExcelFile1.Close
ObjExcelFile2.Close
objExcel.Quit

This answer is correct, however, it is not optimized because you need to traverse each and every row of the column to be pasted in another excel. If you need to dump whole data of any column .i.e from a.xls to another column of b.xls then you can use the following code.

colToFound="LAST_NM"
fileToCopy="D:ExcelDataA.xlsx"
fileToPaste="D:ExcelDataB.xlsx"
Dim objExcelA
Dim objWorkbookA
Dim objWsheetA

Set objExcelA=CreateObject ("Excel.Application")

Set objWorkbookA=objExcelA.Workbooks.Open(fileToCopy)
Set objWsheetA=objExcelA.Sheets.Item("Sheet1")

colNo=objWsheetA.UsedRange.Columns.count
rowsNo=objWsheetA.UsedRange.rows.count
'
For i=1 to colNo
 colVal=objExcelA.Cells(1,i).value
 If (colVal=colToFound) Then
  colToFoundcolNum=i
 End If
next
 colToFoundAddress=split(objExcelPayment.Cells.Find(colToFound).Address,"$",-1)(1)
 objWsheet.Range(""&colToFoundAddress&"1:"&colToFoundAddress&rowsNo&"").select
 objExcelA.Cells(1,colToFoundcolNum).entireColumn.copy

 Set objExcelB=CreateObject("Excel.Application")
 Set objWbookB=objExcelB.Workbooks.Open(fileToPaste)
 Set objWSheetB=objExcelB.Sheets.Item("Sheet1")
 rowsNopaste=objWSheetB.UsedRange.rows.count

 objWSheetB.activate
 coltoPasteAddress=Split(objExcelB.Cells.Find("DESIGNATION").Address,"$",-1)(1)
 objWSheetB.Range(""&coltoPasteAddress&"1:"&coltoPasteAddress&rowsNo&"").select
 objWSheetB.Paste
 objWbookB.Save

 Set objExcelA=Nothing
 Set objExcelB=Nothing
 objWbookB.Close
 objWorkbookA.Close

Regards,
Gajendra 


------------------------------------------------------------------------------------------------------------- '1. Have data in a.xls file that has 12 columns '2. Would like to get values from column 8 th 11 th and write it to b.xls file on columns 4 and 5th. '------------------------------------------------------------------------------------------------------------ Dim objExcel Set objExcel = CreateObject("Excel.Application") objExcel.Visible = True Set ObjExcelFile1 = objExcel.Workbooks.Open("D:ABCa.xls") Set ObjExcelSheet1 = ObjExcelFile1.Sheets("Sheet1") Set ObjExcelFile2 = objExcel.Workbooks.Open("D:ABCb.xls") Set ObjExcelSheet2 = ObjExcelFile2.Sheets("Sheet1") For i = 1 to ObjExcelSheet1.UsedRange.Rows.Count strValue = ObjExcelSheet1.Cells(i 8) ObjExcelSheet2.Cells(i 4) = strValue strValue1 = ObjExcelSheet1.Cells(i 11) ObjExcelSheet2.Cells(i 5) = strValue1 Next ObjExcelFile2.Save ObjExcelFile1.Close ObjExcelFile2.Close objExcel.Quit

  Was this answer useful?  Yes

set excel=createobject("word.application")
set document=excel.documents.add
excel.visible=true
excel.selection.font.size=20
excel.selection.typetext "my name is Mahesh Reddy"
document.saveas "path name"
document.close

  Was this answer useful?  Yes

Asik

  • Aug 8th, 2011
 

Hi,

I have a Notepad which has Rows and Columns , ie a Report(Notepad) created on Run in my application.

Now i want to Read the Data C*R wise, i mean

X Y Z P Q R S

1 2 3 4 5 6 7

i want to use X's value to the Next Test Case as 1

please Help me?

Thanks in Advance

Asik

  Was this answer useful?  Yes

Gajendra Sharma

  • Aug 8th, 2011
 

Hi Asik,

Can you please elaborate your question: I want to know what exactly do you want to achieve. Are there multiple rows for columns or only one column and one row in your report. If there are multiple rows, then do you want to Read value in 2nd row and 3rd row of Column X and multiply those values? Please, take an example with 2 or 3 rows and what exactly you want to achieve.....

Regards,
Gajendra Sharma
================
X Y Z P Q R S

1 2 3 4 5 6 7

i want to use X's value to the Next Test Case as 1

====================================

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions