Solved

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

Posted on 2004-08-13
6
283 Views
Last Modified: 2010-04-23
How can i read the 3rd line of a text file only ?
0
Comment
Question by:Vartana
  • 3
  • 2
6 Comments
 
LVL 18

Accepted Solution

by:
DotNetLover_Baan earned 450 total points
ID: 11797472
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
 
LVL 7

Assisted Solution

by:natloz
natloz earned 50 total points
ID: 11797473
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
 
LVL 1

Author Comment

by:Vartana
ID: 11797687
This dosnt work  How can i read the 3rd line ?
0
ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11798027
What do you mean it doesn't work... ?  I tested it.. and it is giving me the third line...
0
 
LVL 1

Author Comment

by:Vartana
ID: 11798029
ok it works sorry :(

Thank you much
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 11798044
happy programming... :))
cheers...
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question