0

Hi,

I have come to ask about "System.IO.StreamReader.ReadLine"
I want it to read line 1, then 2, then 3, and it keeps going for 20

Please just give me the code to read line 5 for example, then i will do the rest, here is the code for you to work on

Dim loadf As New System.IO.StreamReader("c:/text.txt")
        textbox5.Text = loadf.ReadLine()

Thats really all i know, please help

Thanks, Luke

2
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by manal
0

to read from file line by line you need to use ReadLine method as you did , plus checking if you reached the end of file or not by Peek method

While loadf.Peek <> -1
            Line = loadf.ReadLine()
           ...
           ...
        End While

Please just give me the code to read line 5 for example, then i will do the rest,

i am not sure if I understand you, you want to write line 5 in the textbox? then in the while loop above check if you reached line 5 by counter then if yes show the line in textbox

n = 0
        While loadf.Peek <> -1
            n = n + 1
            Line = loadf.ReadLine()
            If n = 5 Then
                  TextBox1.Text = Line
            End If

        End While
0

Hi, yes i meant to write the text in line 5 to textbox1 for example. Please just confirm that the code you used would work,
Thanks,
Luke

0

:) to learn how to program you need to try at first then learn from your mistakes
however, yes that code should read the line 5 to textbox

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.