Solved

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

Posted on 2004-08-13
6
277 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

911 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now