|
-
Jan 4th, 2004, 03:09 PM
#1
Thread Starter
Member
Monitoring text file [RESOLVED]
Hi All
I wonder if someone can help me, my program monitors a text file and always monitors the last line of the text file for a specific line entry. Can anybody tell me how I ignore the last line of my text file and wait for a new entry to appear when my program first starts monitoring the file.
Also can anybody tell me if it is possible to read the file from mutilple sources at the same time.
Thanks for any help
Scouseman
Last edited by scouse; Jan 6th, 2004 at 07:35 AM.
-
Jan 4th, 2004, 03:13 PM
#2
Fanatic Member
hmm
how do you currently monitor the last line of your textfile?
do you read it into memmory, line for line...until you reach the last line?
-
Jan 4th, 2004, 03:16 PM
#3
Thread Starter
Member
Hi TokersBall_CDXX
This is the code I currently use to read the last line:
Private Sub Timer3_Timer()
Dim Strarr As String
Open "c:\system1.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, Strarr
Loop
Close #1
signal() = Split(Strarr, ",")
End Sub
Thanks for your time
Scouse
-
Jan 4th, 2004, 03:21 PM
#4
Lively Member
Put the last line into a string and textbox use a conditonal like
if strText = txtText then
do nothing
else
do this
end if
then just compare the new data with the old in the textbox!!
-
Jan 4th, 2004, 03:32 PM
#5
Lively Member
VB Code:
Private Sub Timer3_Timer()
Dim Strarr As String
Dim strLTime As String
Open "c:\paltalk.bbc" For Input As #1
Do While Not EOF(1)
Line Input #1, Strarr
Loop
Close #1
If strLTime = Strarr Then
Exit Sub
Else
signal = Split(Strarr, ",")
End If
strLTime = Strarr 'do this for next time to test if there the same
End Sub
That should do what u need i dont know what exaclty your splitting to text it
-
Jan 4th, 2004, 04:18 PM
#6
scouse
First never read the whole file to get to the end. Not efficient.
Position yourself at the end of the file (In Binary mode)
Read a chunk of the file (backwards of course)
Search the buffer backwards for end of line (Second one of course)
Now you are at the last line of the file.
If the file is large, you will be doing a lot of work for nothing by reading each line (like digging a ditch with a spoon). Sure it will get done (sooner or later), but it would be better to use a shovel or something better.
You can read the file from as many sources as you like (use read only mode).
-
Jan 4th, 2004, 06:40 PM
#7
Thread Starter
Member
Thanks everyone for your help
Much Appreciated
Scouse
-
Jan 5th, 2004, 05:41 AM
#8
Lively Member
How did you end up solving it ?
The method of usi ng random and binary access is indeed faster but alot more work, if your app is big or time critical then id suggest using filelen function and work on reading the files last xxx many letters or other methiods as suggested!
-
Jan 5th, 2004, 03:09 PM
#9
Thread Starter
Member
Hi Cenobitez
I implemented the compare solution but after testing it I realised it would not work. The problem I was having was that there can be two lines in my text file which are identical but I need to know that a new line has appeared in the file.
Thanks anyway for your time and help
Scouse
-
Jan 5th, 2004, 03:18 PM
#10
scouse,
If you are just looking to see if something was added to the file... just check the length of the file. If the file size gets bigger then something was added. Then you check for the last line entry.
-
Jan 5th, 2004, 04:29 PM
#11
Lively Member
Then check the length of the strarr array using
intLen = FileLen(strArr)
then use the same methiod of comparing id nest them like
If intLastLen = intLen then goto skipit
if str1 = str2 then
goto skipit
else
do this
end if
-
Jan 6th, 2004, 03:25 AM
#12
Thread Starter
Member
Thanks everyone I have now got it to works
Thanks for your time
Mark
-
Jan 6th, 2004, 07:33 AM
#13
scouse
Good. Please mark your post resolved.
Thanks
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
|