Read text file which is still updated

Y

Yaniv

Hi

I'm new in VB.NET.
I wrote an application which opens a text file and read it all lines
untill the EOF
this file is open for read only and for sharing asllowed.
every 5 seconds another applications write another line to this file
at the end and I'm trying to read those new lines from my
applications. the problem is that the EOF function returns TRUE even
though a new lines added to this file.
what can I do?

I open the file using the function:
FileOpen(1, File, OpenMode.Input, OpenAccess.Read, OpenShare.Shared)

I read line using the function:
Linet = LineInput(1)

I check EOF with the function:
EOF(1)

Do I need to use diffrent functions for open and read that file?

Thanks for the help...
 
L

lord.zoltar

Yaniv said:
Hi

I'm new in VB.NET.
I wrote an application which opens a text file and read it all lines
untill the EOF
this file is open for read only and for sharing asllowed.
every 5 seconds another applications write another line to this file
at the end and I'm trying to read those new lines from my
applications. the problem is that the EOF function returns TRUE even
though a new lines added to this file.
what can I do?

I open the file using the function:
FileOpen(1, File, OpenMode.Input, OpenAccess.Read, OpenShare.Shared)

I read line using the function:
Linet = LineInput(1)

I check EOF with the function:
EOF(1)

Do I need to use diffrent functions for open and read that file?

Thanks for the help...

Maybe close the file after reading, then reopen it after 5 seconds.
It's simple, but that would be a lot of file opening and closing...
Instead, maybe have a bookmark variable keep track of the number of
lines you have read. Then, after 5 seconds, seek back to the bookmark
(there's a procedure that lets you set the position in the file
stream) and start reading again. You'd have to change your reading
loop a bit.
 
Y

Yaniv

Thanks.

Could you please tell me which function does that ?
Is there a code sample anywhere in the internet for this?

(e-mail address removed) כתב:
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Yaniv said:
Hi

I'm new in VB.NET.
I wrote an application which opens a text file and read it all lines
untill the EOF
this file is open for read only and for sharing asllowed.
every 5 seconds another applications write another line to this file
at the end and I'm trying to read those new lines from my
applications. the problem is that the EOF function returns TRUE even
though a new lines added to this file.
what can I do?

I open the file using the function:
FileOpen(1, File, OpenMode.Input, OpenAccess.Read, OpenShare.Shared)

I read line using the function:
Linet = LineInput(1)

I check EOF with the function:
EOF(1)

Do I need to use diffrent functions for open and read that file?

Thanks for the help...

I believe that you have to close the file and open it again to get a
file handle with the new file size.

If you only want to read the added lines, you can periodically check for
a change in the file size. When it changes you can open the file as a
binary file, seek to the previos file end and read the remaining bytes.
Then you can use the Encoding.UTF8 object to decode the bytes into a string.

However, reading a file that is being written to is a bit shaky. If
possible, perhaps you should consider an alternative way of storing the
information, like for example a database table. A database is better
equipped to handle simultaneous reading and writing of data than the
file system is.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top