1.

Solve : How do I read from a spesific line in a .txt file in VB 2008??

Answer»

I believe the title covers it all but...

Code: [Select] Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim loadf As New System.IO.StreamReader("E:/sinistradc/save.txt")
loadf.ReadLine()
loadf.Close()
End Sub
that is as far as I have gotten.

Thanks in advance,
SimitraText files use sequential access methods, so you'll need to loop through the file until you find your record.

Code: [Select]Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim loadf As New System.IO.StreamReader("E:/sinistradc/save.txt")
Dim strContent As String
Do
strContent = loadf.ReadLine()
Loop Until strContent Is NOTHING
loadf.Close()
End Sub

How will you recognize this specific record?

If you looking for a record based on it's position in the file, maintain a counter inside the loop. For INSTANCE, if you want the 47TH record, when the counter reaches 47, the data you're looking for will be in strContent.

If you looking for a record with specific values, there are MANY functions available including mid, instr, left, right, etc

If the file is delimited, use the split function to parse the data.

As written, after each read, the CONTENTS of the record are in strContent.

Good luck.



Discussion

No Comment Found