Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have a text file that contains this info:

VB
ASKK90001BRANCH
COMPANY-HONDAHCMI
01
HCAISD-02


i tried using this code:
VB
Dim objReader As New System.IO.StreamReader(Application.StartupPath & "\SQ.txt")
LBLcounter.Text = objReader.ReadToEnd
objReader.Close()


but it reads everything and when i change 'ReadToEnd' to 'ReadLine', it only reads the first.

how do I read the 3rd line of the text? the '01'?
Posted
Updated 14-May-17 3:45am
v2

I found out a very easy way.

VB
Dim Counter As String = System.IO.File.ReadAllLines(Application.StartupPath& "\SQ.txt")(2)
LBLcounter.text = Counter


the (2) is the number of the line of the text.
 
Share this answer
 
try like below
VB
Dim line As String
Using sr As StreamReader = New System.IO.StreamReader(Application.StartupPath & "\SQ.txt")
  line = sr.ReadLine()
  While (line <> Nothing)
      line = sr.ReadLine()
  End While
End Using
 
Share this answer
 
Comments
charliedev 24-Jun-14 1:47am    
doesn't work with me :/ it gives me a blank line

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900