Text File Help

darknuke

Well-known member
Joined
Oct 3, 2003
Messages
68
How would I go about reading a single line from a text file that I specify?

Example:

line1
line2
line3
line4

How would I just retrieve line3?
 
This isnt for a company called Display Pack is it?
Well if it is ill still help you out.
Dim sr As New System.IO.StreamReader("C:\Text.txt")
Dim line As String
Dim x As Integer
Do Until sr.Peek = -1
x += 1
line = sr.ReadLine
If x = 3 Then this will return the 3rd element
TextBox1.Text = line This will input everything from line 3 into a textbox
Exit Do
End If


Loop
dont forget to close the stream reader object when your done with it.
sr.close() this closes it
Or you could make line an array and store all lines in there then just query your array with the correspondiing line number
 
Last edited by a moderator:
Actually i prefer this way to the Legacy VB6 way the Line input #
VB is becoming to verbose for me .
 
No, Im making a server file serving program for users and I need to check in a text file for what files they can download and their username/password information. =D
 
I do use lineinput(), but that cant access lines for checking passwords, I use it to list usernames.
 
Back
Top