Solved

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

Posted on 2004-08-13
6
286 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VS.net 2010 11 48
VB.NET 2008 Winforms Signing 13 32
Create a datatable in vb.net dynamically 1 22
FInd Image Control Gridview 3 22
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…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

827 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