Hello
I would like to read a file and display certain lines ( like from line 5 to 10) in a label. i know how to read the file line by line but not the specified line i want.
Thanks in advance
Hello
I would like to read a file and display certain lines ( like from line 5 to 10) in a label. i know how to read the file line by line but not the specified line i want.
Thanks in advance
Read the file line by line and when you get to the line you want, stop. Might need an if
statement
I am not so sure what you mean. My current code is:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myfile As String = "C:\Users\londonG\Documents\lillefile.txt"
Dim TextLine As String
If System.IO.File.Exists(myfile) = True Then
Dim objReader As New System.IO.StreamReader(myfile)
Do While objReader.Peek() <> -1
TextLine = TextLine & objReader.ReadLine() & vbNewLine
Loop
TextBox1.Text = TextLine
End If
End Sub
Where should i put the if statement. Is it inside the loop?
How should I write it?
Thank you
I am not so sure what you mean. My current code is:
Maybe you should have posted this last time... :icon_wink:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim myfile As String = "C:\Users\londonG\Documents\lillefile.txt" Dim TextLine As String If System.IO.File.Exists(myfile) = True Then Dim objReader As New System.IO.StreamReader(myfile) Do While objReader.Peek() <> -1 TextLine = TextLine & objReader.ReadLine() & vbNewLine Loop TextBox1.Text = TextLine End If End Sub
Where should i put the if statement. Is it inside the loop?
How should I write it?
Thank you
Are you asking me to write it for you? What does your code do currently? Where do you think the if
should go?
and perhaps Walt you should recognize that this thread is in the wrong forum and have moved it to the VB.NET forum...
Thanks WaltP.
>I would like to read a file and display certain lines ( like from line 5 to 10) in a label.
ReadAllLines() method of File class will solve your problem.
Dim lines() As String = System.IO.File.ReadAllLines("file_path")
Ok,
Thank you very much for your help. I done it now :-)
Please review my thread. It will help you in this problem...
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.