Solved

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

Posted on 2004-08-13
6
273 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
Comment Utility
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
Comment Utility
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
Comment Utility
This dosnt work  How can i read the 3rd line ?
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 18

Expert Comment

by:DotNetLover_Baan
Comment Utility
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
Comment Utility
ok it works sorry :(

Thank you much
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
Comment Utility
happy programming... :))
cheers...
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

12 Experts available now in Live!

Get 1:1 Help Now