Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Editing a notepad file in QTP
#6
Solved: 12 Years, 10 Months, 3 Weeks ago
Thanks rajpes for ur time. I have already thought of your suggestion first. I dont want to delete and create again. I want to do it in one shot.

I found one solution for it..and it is working for me.

My objective was to open a notepad, get its content, perform some matematical operations and generate a new string and finally write the new string to the file..



Code:
Const ForReading = 1, ForWriting = 2
Const TristateUseDefault = -2

strFilePath="C:\xyz.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set fileObject = fso.GetFile(strFilePath)
Set ts = fileObject.OpenAsTextStream(ForReading, TristateUseDefault)
objText = ts.ReadLine
print objText

strTest=Split(objText,vbTab)

'Split and get the value
strVar1=strTest(0)
strVar2=strTest(1)
strVar3=strTest(2)
strVar4=strTest(3)
strVar5=strTest(4)
strVar6=strTest(5)
strVar7=strTest(6)
strVar8=strTest(7)
strVar9=strTest(8)
strVar10=strTest(9)

'Get the values on which the operation has to be performed
strVar5=strVar5+1
strVar6=strVar6+1
strVar7=strVar7+0.01
strVar8=strVar8+0.01
strVar9=strVar9+0.01
strVar10=strVar10+0.01

'Create a new string to be written to file
strNewString=strVar1&vbTab&strVar2&vbTab&strVar3&vbTab&strVar4&vbTab&strVar5&vbTab&strVar6&vbTab&strVar7&vbTab&strVar8&vbTab&strVar9&vbTab&strVar10

print strNewString
ts.Close

'Open the file and write the content to the file. This will replace the old content
Set ts = fileObject.OpenAsTextStream(ForWriting, TristateUseDefault)
ts.Write strNewString
ts.Close
Set fso=Nothing


Regards,
Ankesh
Reply


Messages In This Thread
Editing a notepad file in QTP - by arjun.singh - 03-23-2009, 03:35 PM
RE: Editing a notepad file in QTP - by Ankesh - 10-20-2011, 05:59 PM
RE: Editing a notepad file in QTP - by rajpes - 10-20-2011, 06:31 PM
RE: Editing a notepad file in QTP - by Ankesh - 10-20-2011, 06:58 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Fifth word from every thousand line in notepad files. sallu.iet@gmail.com 0 3,379 01-17-2020, 09:58 AM
Last Post: sallu.iet@gmail.com
  QTP 11 Evaluation installation file not having executable file Akhila 2 4,701 10-19-2012, 12:04 AM
Last Post: gdp9600
  Script Editing Problem neerdeth 4 4,119 07-20-2012, 10:12 AM
Last Post: Shridevi.Salagare
  Copy Data from Notepad jegansurya 3 7,474 07-04-2012, 05:31 PM
Last Post: Shridevi.Salagare
  Cannot find the "Edit" object's parent "Notepad" gnanajyothi 1 3,485 04-09-2012, 11:12 AM
Last Post: sshukla12

Forum Jump:


Users browsing this thread: 2 Guest(s)