473,804 Members | 3,312 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Read text file which is still updated

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.Share d)

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...

Feb 19 '07 #1
3 4228

Yaniv wrote:
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.Share d)

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.

Feb 19 '07 #2
Thanks.

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

lo*********@gma il.com כתב:
Yaniv wrote:
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.Share d)

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.
Feb 19 '07 #3
Yaniv wrote:
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.Share d)

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.

--
Göran Andersson
_____
http://www.guffa.com
Feb 19 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
4231
by: John | last post by:
I just learned that it is possible to grab a text file from another site and display the data on my own site, however when I display the data it does not format it correctly. Can anyone please point me in the direction of a tutorial or help me with the code below. John <% Response.Buffer = True Dim objXMLHTTP, xml
12
11669
by: Steven T. Hatton | last post by:
I know of a least one person who believes std::ifstream::read() and std::ofstream::write() are "mistakes". They seem to do the job I want done. What's wrong with them. This is the code I currently have as a test for using std::ifstream::read(). Is there anything wrong with the way I'm getting the file? #include <vector> #include <iomanip> #include <fstream> #include <iostream>
5
3164
by: Martin Svensson | last post by:
Hello! I need some help/recommendations on how to do the following. I have a program that writes an IP address two control numbers and a date to file, on one line. It's a basic text file and it looks like this: ----- beginning of file ----- 192.168.0.1 0 0 2004-08-01 192.168.0.2 1 0 2004-08-21 192.168.0.4 0 1 2004-08-12
35
11511
by: RyanS09 | last post by:
Hello- I am trying to write a snippet which will open a text file with an integer on each line. I would like to read the last integer in the file. I am currently using: file = fopen("f.txt", "r+"); fseek(file, -2, SEEK_END); fscanf(file, "%d", &c); this works fine if the integer is only a single character. When I get into larger numbers though (e.g. 502) it only reads in the 2. Is there
8
1891
by: kepioo | last post by:
I currently have an xml input file containing lots of data. My objectiv is to write a script that reports in another xml file only the data I am interested in. Doing this is really easy using SAX. The input file is continuously updated. However, the other xml file should be updated only on request. Everytime we run the script, we track the new elements in the input file and report them in the output file.
3
1338
gsgurdeep
by: gsgurdeep | last post by:
Good Morning I want to display text of a notepad file on a html page. File is randomly updated any time by an employ. after update html page should be updated autometically. tell me the solution.
1
1833
by: Sagar | last post by:
I want to write a program, that reads and logs the windows events that happened in a particular folder once every minute, 1. A file was created in the folder. which user created ? 2. A file was updated in the folder, which user updated ? 3. A file was deleted from the folder, which user deleted ? My question is, Is it possible to read the instance and info of the above said 'windows events' using vb.net ?
2
3248
by: Eric | last post by:
Hi, There is a textbox which contains some text. The purpose is to update the text manually into the textbox and send (update) the updated text to the database. My problem is that when i click on button2, variable 'txt' contains the original text and not the manually updated text. I must forget something but can't find it right now.
4
3420
by: Keith G Hicks | last post by:
I'm trying to read a text file and alter the contents of specific lines in the file. I know how to use streamreader to read each line of a file. I'm doing that already to get the data into a database. What I need help with is on how to locate a specific line in the file, change it and then save the updated text file. Can anyone help me out or point me to a site that explains this clearly? Here's part of my code that reads the contents of...
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10564
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10308
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10073
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6846
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5513
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5645
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3806
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2981
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.