Does anybody have suggestion on how to read and write to a text file with UFT GUI?
Question ID: 106567
0
0

Does anybody have suggestion on how to read and write to a text file with UFT GUI? Any suggestions?

Marked as spam
Posted by (Questions: 63, Answers: 1)
Asked on January 5, 2016 3:03 pm
46 views
Answers (3)
0
Private answer

HP has great document to reference this question Check out [KM171403][1].

Here is write example:

' Write some data to a file.
Dim fso, MyFile
Set fso = CreateObject(''Scripting.FileSystemObject'')
Set MyFile = fso.CreateTextFile(''C:testfile.txt'', True)
MyFile.WriteLine(''This is a test'')
MyFile.WriteLine(''This is another test'')
MyFile.Close

Here is the read example:

' Read the data from the file.
Dim fso, MyFile
Set fso = CreateObject(''Scripting.FileSystemObject'')
Set MyFile = fso.OpenTextFile(''C:testfile.txt'')
MsgBox MyFile.ReadLine
MsgBox MyFile.ReadLine
MyFile.Close

[1]: https://softwaresupport.hp.com/group/softwaresupport/search-result/-/facetsearch/document/KM171403

Marked as spam
Posted by (Questions: 2, Answers: 98)
Answered on January 5, 2016 3:08 pm
0
Private answer

You can also use some advanced techniques when reading from text files, like looping to the end of the doc and splitting text up into arrays if you need to use sections of it for data driving a test:

http://eyeontesting.com/questions/3545/i-want-to-use-a-text-file-for-data-in-qtp-11.html

Marked as spam
Posted by (Questions: 2, Answers: 477)
Answered on January 5, 2016 4:12 pm
0
Private answer

Also, keep in mind that the FileSystemObject allows you to create files of different extensions as long as they are text files. You can create .CSV, .RTF, etc. using the same object and just change the filename you are either writing to or reading from.

Marked as spam
Posted by (Questions: 2, Answers: 477)
Answered on January 5, 2016 4:16 pm
EyeOnTesting

Welcome back to "EyeOnTesting" brought to you by Orasi Software, Inc.

X
Scroll to Top