My my isn't working correctly right now... How do I the easiest way get the 20 last items in a text file?
Big thanks!
Printable View
My my isn't working correctly right now... How do I the easiest way get the 20 last items in a text file?
Big thanks!
20 last items of...what? A listbox? An array? A Grid?
By "the 20 last items" do you mean the last 20 rows of text?
If every line is separated with a newline then use the Split function to get an array with each line in it.
In the textfile there are hundreds or even thousands of values. It could look like this:
5,4,3,8,66,44,3,4,5
I am only interested in the last twenty of these. I guess I can use spilt to make an array.
You can try this:
Dim Values(20) as String
Dim FromFile As (whatever the values are, perhaps Integer)
Dim I as Byte
' file 1 must already be open
Do until EOF(1)
Input #1, FromFile
For I = 1 to 19
Values(I) = Values(I + 1)
Next I
Values(20) = FromFile
Loop
This should end up with the last 20 items. It might be slow on Really big files, but it should do the job.