Wednesday, 19 October 2011

QTP Script: Example of how to read a text file line-by-line


' reading a file line by line

Const ForReading = 1

' create file system object
Set objFS = CreateObject("Scripting.FileSystemObject")

' first check that the file exists
If objFS.FileExists("c:\TextFile.txt"Then

    ' open the text file for reading
    Set objFile = objFS.OpenTextFile("c:\TextFile.txt"ForReadingFalse)

    ' do until at end of file
    Do Until objFile.AtEndOfStream

        ' store the value of the current line in the file
        strLine = objFile.ReadLine

        ' show the line from the file
        MsgBox strLine

    Loop ' next line

    ' close the file
    objFile.Close

    Set objFile = Nothing

Else ' file doesn't exist

    ' report a failure
    Reporter.ReportEvent micFail"Read File""File not found"

End if ' file exists

' destroy the objects
Set objFS = Nothing

7 comments:

  1. Do you have a spam issue on this blog; I also am a blogger,
    and I was wondering your situation; many of
    us have created some nice procedures and we are looking to exchange strategies with other folks, please shoot
    me an e-mail if interested.

    my website; planet minecraft

    ReplyDelete
  2. Does your site have a contact page? I'm having a tough time
    locating it but, I'd like to shoot you an e-mail. I've got
    some suggestions for your blog you might
    be interested in hearing. Either way, great blog and I
    look forward to seeing it improve over time. Quest Bars blogesaurus

    my page :: quest protein bars

    ReplyDelete
  3. Just wish to say your article is as astounding.

    The clarity to your put up is simply great and that i could think you are
    a professional on this subject. Fine together with your permission let me
    to seize your feed to stay updated with forthcoming post.
    Thank you a million and please carry on the enjoyable work.



    Feel free to surf to my homepage; facebook quest protein bar

    ReplyDelete
  4. What's up it's me, I am also visiting this web page on a regular basis,
    this website is truly fastidious and the visitors are in fact sharing nice thoughts.


    Here is my blog post; Diet Plans for Women

    ReplyDelete
  5. hello!,I like your writing very much! share we communicate extra approximately
    your post on AOL? I require an expert in this area to resolve my problem.
    Maybe that's you! Taking a look ahead to look you.

    Check out my web page ... Lose Weight for Women

    ReplyDelete
  6. hi!,I like your writing very a lot! share we keep in touch more approximately your post
    on AOL? I need an expert in this area to resolve my problem.
    May be that's you! Looking forward to peer you.


    Here is my webpage; Diet Plans for Women to Lose Weight

    ReplyDelete
  7. Pretty element of content. I just stumbled upon your weblog and in accession capital to assert that I get in fact loved account your
    weblog posts. Anyway I'll be subscribing in your feeds and even I achievement you get admission to
    persistently fast.

    my page Diet Plans for Women to Lose Weight

    ReplyDelete