[Help] Read a textfile line-by-line.

Posts 1–7 of 7 · Page 1 of 1
[Help] Read a textfile line-by-line.
Dunno how, and want to know.

Never taught myself how, I guess :/
You mean like if your opening one like notepad?

well then

Code:
Dim x As New IO.StreamReader(OpenFileDialog1.FileName)
        TextBox1.Text = x.ReadToEnd 
        x.Close()
Using sRead As New IO.StreamReader("File")
Dim Line1 As String = sRead.ReadLine
Dim Line2 As String = sRead.ReadLine
Dim Line3 As String = sRead.ReadLine
Dim Line4 As String = sRead.ReadLine
Dim Line5 As String = sRead.ReadLine

'etc....
End Using

That is to read line by line as you said, If you want to read Everything then say it :P
[highlight=vb.net]
Dim sReader As New IO.StreamRead("C:\textfile.txt")
Dim txtContents As String = String.Empty
While Not sReader.EndOfStream
txtContents += sReader.ReadLine & vbNewLine
End While
sReader.Close
[/highlight]
anyone know a For Each?

Dim sReader As New IO.StreamRead("C:\textfile.txt")
Dim txtContents As String = String.Empty
While Not sReader.EndOfStream
* * txtContents += sReader.ReadLine & vbNewLine
End While
sReader.Close


Thanks @master131
ôh that.


You said lineby line so i trough that xD
Line by line would be like this:

[highlight=vb.net]
Dim totalLines As String() = IO.File.ReadAllLines("C:\Example\yeah.txt")
For each line As String in totalLines
'....
Next
[/highlight]

Kids stuff
Posts 1–7 of 7 · Page 1 of 1
This thread is closed for replies.
Talk with us