|
-
May 22nd, 2007, 07:57 AM
#1
Thread Starter
Hyperactive Member
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
-
May 22nd, 2007, 08:11 AM
#2
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
-
May 22nd, 2007, 08:29 AM
#3
Thread Starter
Hyperactive Member
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
-
May 22nd, 2007, 09:13 AM
#4
Re: I want to read a file starting from the last line in the page
Ehhh... there is a typo:
repalce this: arLines = Split(sText(, vbNewLine))
with this: arLines = Split(sText, vbNewLine)
Sorry about that.
-
May 22nd, 2007, 09:18 AM
#5
Re: I want to read a file starting from the last line in the page
 Originally Posted by RhinoBull
repalce this: arLines = Split(sText(, vbNewLine))
I thought you had come up with an undocumented way of using Split.
-
May 22nd, 2007, 09:31 AM
#6
Re: I want to read a file starting from the last line in the page
Hah, I guess I just did.
-
May 22nd, 2007, 09:53 AM
#7
PowerPoster
Re: I want to read a file starting from the last line in the page
 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.
-
May 22nd, 2007, 12:25 PM
#8
Thread Starter
Hyperactive Member
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?
-
May 22nd, 2007, 12:27 PM
#9
PowerPoster
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.
-
May 22nd, 2007, 12:29 PM
#10
Thread Starter
Hyperactive Member
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"?
-
May 22nd, 2007, 12:33 PM
#11
PowerPoster
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.
-
May 22nd, 2007, 01:02 PM
#12
Re: I want to read a file starting from the last line in the page
 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))
-
May 22nd, 2007, 06:40 PM
#13
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|