Results 1 to 13 of 13

Thread: I want to read a file starting from the last line in the page

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    507

    I want to read a file starting from the last line in the page

    I am trying to find a way to read a file starting from the last line in the page, reason why I Want to do that, because this file is always updated and I am watching this file to do something when it find an specific errors. The word could be found in more then one place in the file, by reading the last line this way I don't have to worry if this same error existed before in the file.

    Any help is appreciated.

    Thanks

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: I want to read a file starting from the last line in the page

    Try the following - hopefully it works for you:
    Code:
    Dim sFile As String
    Dim sText As String
    Dim arLines() As String
    Dim LastLine As String
    Dim i As Long
    
        sFile = App.Path & "\mydata.txt"
        Open sFile For Input As #1
            sText = Input(LOF(1), #1)
            arLines = Split(sText(, vbNewLine))
        Close #1
        sText = ""
        
        LastLine = arLines(UBound(arLines))
        Debug.Print arLines
        
        'or loop if you need to
        For i = UBound(arLines) To LBound(arLines) Step -1
            Debug.Print arLines(i)
        Next i

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    507

    Re: I want to read a file starting from the last line in the page

    Thanks Rhino, I am getting an error on sTEXT, error msg "Expected Array"
    why is that? i Place this code in COMMAND CLick

  4. #4

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: I want to read a file starting from the last line in the page

    Quote Originally Posted by RhinoBull
    repalce this: arLines = Split(sText(, vbNewLine))
    I thought you had come up with an undocumented way of using Split.

  6. #6

  7. #7
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: I want to read a file starting from the last line in the page

    Quote Originally Posted by wajdi
    I am trying to find a way to read a file starting from the last line in the page, reason why I Want to do that, because this file is always updated and I am watching this file to do something when it find an specific errors. The word could be found in more then one place in the file, by reading the last line this way I don't have to worry if this same error existed before in the file.

    Any help is appreciated.

    Thanks
    If you are regularly rechecking the *SAME* file for changes, I suggest you do this:

    1) Store LOF (length of file) for the file after each check
    2) ONLY load in new data from the point stored in the previous LOF to the current LOF...if these two values match you know it hasn't changed, of course and can just ignore the check

    This will greatly speed up your checking because you won't have to recheck stuff time and time again

    This is easy to do and if you require further help, people here will help you with "random access" to files and how exactly to achieve what I suggested above. I could do it, but I dunno if I will be around :-)
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    507

    Re: I want to read a file starting from the last line in the page

    Thanks guys for your help, RIHNO, why am I getting in at this line "' Debug.Print arLines" Type Mismatch?

  9. #9
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: I want to read a file starting from the last line in the page

    You can remove that line...any debug.print lines are used for debugging and it's just showing you what the result is...

    ...however, if you want to fix it, change the "arLines" to "arLines(UBound(arLines))"
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    507

    Re: I want to read a file starting from the last line in the page

    THanks sMUX, I am a bit comfused here, how I use this code to look for "updates detected"?

  11. #11
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: I want to read a file starting from the last line in the page

    My suggestion is to go back to the original post I made...if you were looking for the word "five" in this string with the code I suggested you write (or ask someone to help with):

    "onetwothreefourfivesixseven"

    it would find it the first time then would take the length of this string and remember it. Next time it checks for "five" it would look in:

    "onetwothreefourfivesixseveneightninetenonetwothreefourfivesix"

    it would start at the end of "seven" and find the *second* "five"
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  12. #12
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: I want to read a file starting from the last line in the page

    Quote Originally Posted by wajdi
    ...why am I getting in at this line "' Debug.Print arLines" Type Mismatch?
    because it was free hands typing thing ...
    Anyway you need to learn how to fix this sort of error - the index is missing...

    Use this instead:
    Debug.Print arLines(UBound(arLines))

  13. #13
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: I want to read a file starting from the last line in the page

    This project should help you do what you want to do. Look at the top of the page for the Automatic Log File Updater

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