• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 294
  • Last Modified:

VB.NET Read the 3rd line of a text file only ?

How can i read the 3rd line of a text file only ?
0
Vartana
Asked:
Vartana
  • 3
  • 2
2 Solutions
 
DotNetLover_BaanCommented:
Hi there, use readLine method of a StreamReader.

        Dim StreamRd As FileStream
        'Check if the file is there.
        If File.Exists("C:\Data.txt") Then
            StreamRd = New FileStream("C:\Data.txt", FileMode.Open, FileAccess.Read)
        Else
            MsgBox("OOPS!! CEIP_Upload.txt not found")
            Exit Sub
        End If
        'Create reader and read from the file
        Dim FileReader As New StreamReader(StreamRd)
        TextBox1.Text = FileReader.ReadLine 'Show the first Line in a text box.
        'Read twice and you are in the 3rd line
        FileReader.Close()
-Baan
0
 
natlozCommented:
oRead = oFile.OpenText(“C:\sample.txt”)
dim count = 1

 While oRead.Peek <> -1      
   if count = 3 then
      LineIn = oRead.ReadLine()
   end if
   count = count + 1
 End While

 oRead.Close()
0
 
VartanaAuthor Commented:
This dosnt work  How can i read the 3rd line ?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
DotNetLover_BaanCommented:
What do you mean it doesn't work... ?  I tested it.. and it is giving me the third line...
0
 
VartanaAuthor Commented:
ok it works sorry :(

Thank you much
0
 
DotNetLover_BaanCommented:
happy programming... :))
cheers...
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now