Forum Discussion

mmcdonald's avatar
mmcdonald
Occasional Contributor
15 years ago

searching text files

I'm testing a product and want to create a checkpoint which can check for events within the product's log files while the product test runs.

The log files are simple text files with a time and date stamp on each line followed by the event eg:



16/02/10 12:01:17 Connecting to Server on 127.0.0.1 port 12001

16/02/10 12:01:17 Connected to Server



16/02/10 12:04:39 Error creating a new run







so far I have been opening the log in notepad and using a property check point similar to:

Call aqObject.CompareProperty(Aliases.notepad.wndNotepad.Edit.wText, cmpContains, "error connecting", false) 





However obviously this is only good for checking if there has ever been an error anywhere in the log.  Is there anyway I can check specific lines of a text file?  For example could I use the aqDateTime.Time() to get the current time and then check if there is an error line in the log files at the current time (whilst ignoring any previous errors which might have occured)? Or is there another way I haven't thought of?

3 Replies

  • Hi Matthew,



    You need to work with your log files directly via the aqFile object. It allows reading their contents as strings, you can either read the entire file at once or read it line by line. In the lines you obtain from a file, you can search for the needed values.

    See the "Working With Files From Scripts" and "Working With Strings" help topics.

  • mmcdonald's avatar
    mmcdonald
    Occasional Contributor
    thanks for that.  although I tried opening my log files using the line



    logfile = aqFile.OpenTextFile(AFileName, aqFile.faRead, aqFile.ctANSI)







    and this will work for a random text file I created but when I try and open the actual log files from my program I get a VB runtime error "could not open file".  any idea what might be causing this?

  • mmcdonald's avatar
    mmcdonald
    Occasional Contributor
    I just tried again using the FileSystemObject instead of the aqFile object and it seems to work now...