I have text files that store data. Once open (no problem there) I need to read the fourth line from the bottom for use in my program. I'm using text files of varying length so going from the top won't work. Ideas?
I suggest you use arrays for this. Store each line in an element of an array. Then you can simply use uBound -3. Like this:
Code:
Dim Data() As String
Data = Split(CreateObject("Scripting.FileSystemObject").OpenTextFile("[!]C:\Lines.txt[/!]").ReadAll, vbCrLf)
Call MsgBox(Data(UBound(Data) - 3))
Make sure you replace the filename without whatever file you are using.
-George
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
Try
Dim lines() As String = IO.File.ReadAllLines(My.Computer.FileSystem.SpecialDirectories.Desktop + "\lines.txt")
MessageBox.Show(lines(lines.Length - 4))
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.