|
-
Feb 28th, 2009, 09:55 PM
#1
Thread Starter
New Member
continous reading of text file...
please help...i need to make a program that continuously reads a text file(*.txt) and it only stops when you close the program...the condition is this...when you run the program it reads the first line of the text file continuously while there's another program that continuously write in the text file...
please help...thanks in advance..
-
Feb 28th, 2009, 10:42 PM
#2
Re: continous reading of text file...
Welcome to the forums?
Why read the 1st line continuously? The other program is writing to the file how? Appending, overwriting while it is opened, or replacing the file?
More details would be helpful.
-
Feb 28th, 2009, 11:19 PM
#3
Thread Starter
New Member
Re: continous reading of text file...
the reason why i want to make a program that continuously reads a text file is because i have a project that uses the parallel port which displays a number using 7segment display...it is used to display the available/vacant computers in our internet room...the problem is im using vb6 to program it and i need to link it through a text file while the database in the internet room also access the same text file..which the database program is the one that write to the text file while my program in vb6 reads it and displays the number that the database writes on the text file...
-
Mar 1st, 2009, 10:04 AM
#4
Re: continous reading of text file...
Misunderstood intent of my questions. A file is being continuously updated, ok. How is it being written? These questions will help in providing a solution/recommendation.
1. Is data simply being appended to the end of it everytime, so the file grows & grows?
2. Is the data being overwritten without the file being replaced (the file creation date will not change, but modified date will)
3. Is the file being replaced over & over again (file creation date always changes)
-
Mar 1st, 2009, 10:18 PM
#5
Thread Starter
New Member
Re: continous reading of text file...
sorry i misunderstood your question...
the data is simply being appended to the end of it everytime, so the file grows & grows..
-
Mar 1st, 2009, 10:29 PM
#6
Re: continous reading of text file...
That may be a bit easier to deal with. So you don't need to read the 1st line of the file every time? If you did, it would never change since the new stuff is appended afterwards.
Here is one method that may work and is somewhat common. One such program I use is called "Tail" because it does the following, reading the tail end of the file...
1. Use a timer to re-read new parts of the text file each time the timer fires.
2. When you read the file, cache the file pointer position each time. Next time it is read, you read from that pointer on & cache the pointer for the next timer event. VB's Seek method will return the pointer position and is used to set the pointer position for reading.
3. How you open the file matters. You want to open the file in Binary with Access Read permissions. This allows you to keep the file open while the other app writes to it.
Here is the catch if there is one. The other app may have opened the file preventing read access. You won't know until you try to read the file while the other app is running & writing to it.
Last edited by LaVolpe; Mar 1st, 2009 at 10:37 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|