Results 1 to 13 of 13

Thread: Monitoring text file [RESOLVED]

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2003
    Location
    Liverpool UK
    Posts
    44

    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.

  2. #2
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    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?
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2003
    Location
    Liverpool UK
    Posts
    44
    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

  4. #4
    Lively Member Cenobitez's Avatar
    Join Date
    Mar 2002
    Location
    Manchester, England
    Posts
    101
    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!!

  5. #5
    Lively Member Cenobitez's Avatar
    Join Date
    Mar 2002
    Location
    Manchester, England
    Posts
    101
    VB Code:
    1. Private Sub Timer3_Timer()
    2. Dim Strarr As String
    3. Dim strLTime As String
    4. Open "c:\paltalk.bbc" For Input As #1
    5. Do While Not EOF(1)
    6. Line Input #1, Strarr
    7. Loop
    8. Close #1
    9.  
    10. If strLTime = Strarr Then
    11. Exit Sub
    12. Else
    13. signal = Split(Strarr, ",")
    14. End If
    15. strLTime = Strarr 'do this for next time to test if there the same
    16. End Sub

    That should do what u need i dont know what exaclty your splitting to text it

  6. #6
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    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).

  7. #7

    Thread Starter
    Member
    Join Date
    Nov 2003
    Location
    Liverpool UK
    Posts
    44
    Thanks everyone for your help

    Much Appreciated

    Scouse

  8. #8
    Lively Member Cenobitez's Avatar
    Join Date
    Mar 2002
    Location
    Manchester, England
    Posts
    101
    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!

  9. #9

    Thread Starter
    Member
    Join Date
    Nov 2003
    Location
    Liverpool UK
    Posts
    44
    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

  10. #10
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    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.

  11. #11
    Lively Member Cenobitez's Avatar
    Join Date
    Mar 2002
    Location
    Manchester, England
    Posts
    101
    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

  12. #12

    Thread Starter
    Member
    Join Date
    Nov 2003
    Location
    Liverpool UK
    Posts
    44
    Thanks everyone I have now got it to works

    Thanks for your time

    Mark

  13. #13
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    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
  •  



Click Here to Expand Forum to Full Width