Setting line to read in a text file

Hi,

I have a large-ish text file which is being constantly appended with new information - the file is appended to by a Quickbasic program.

I wanted a VB application to monitor when the file had been modified, then read the new data into a list box; this is basically so I can monitor the text file "in real time" and have a nice slidey bar to look up older information.

I am using the following to open the file etc:


Const ForReading = 1, ForWriting = 2, ForAppending = 3
Dim fs, f

Dim Line As String
Dim CurrNumLines As Long

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile(filespec, ForReading, False)

' Obtain number of lines this time
Do While f.AtEndOfStream <> True

Line = f.readline

Loop


Then I was using the f.line property to determine how many lines there are before deciding which lines to append to my list box.

However, I would prefer not to have to read the entire file every time it is updated so....

Is there a way of setting the "line pointer" into a text file? What I'd like to do is, if the file has been modified, to set the line number to the first of the appended lines and just parse these into the list box.

So, it would be nice to be able to do:

f.line = LastLineRead+1
' Read lines from this point to the EOF

Is there any easy way of doing this with text files or do I have to access the file as binary/use the API etc...

rgds,
Juice

Comments

  • [b][red]This message was edited by infidel at 2002-11-14 11:25:45[/red][/b][hr]
    : I have a large-ish text file which is being constantly appended with new information - the file is appended to by a Quickbasic program.
    :
    : I wanted a VB application to monitor when the file had been modified, then read the new data into a list box; this is basically so I can monitor the text file "in real time" and have a nice slidey bar to look up older information.

    Much easier would be to find an MS-DOS port of the UNIX program, "tail". Cygwin (www.cygwin.com) is what I use. It gives you a real command line that mimics Linux and you can get a ton of free programs with it. It is truly magnificent. To monitor a text file in real-time, you just have to do this:

    tail -f [filename]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion