Open text file and target

nvc944

Member
Joined
Apr 25, 2003
Messages
14
Ok guys what am I missing?

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim FF As Integer
Dim strline As String

FF = FreeFile()
Open c:\test.txt For Input As #FF
Do While Not EOF(FF)
Line Input #FF, strline
TextBox1.Text = TextBox1.Text & strline & vbCrLf
Loop
Close #FF

End Sub


I know the code has changed somewhat.. from vb6 to .net.. but
is it that much diff.? hjehe
 
The proper way to do that is [msdn]System.IO.StreamReader[/msdn].
Example:
Code:
dim readtext as string
Dim reader as new SYstem.Io.StreamReader
readtext = reader.Readline()
 
a little confused how to merge that with what I have.

Dim readtext As String
Dim reader As New SYstem.Io.StreamReader
readtext = reader.Readline()
 
Oh, I thought you wanted just any example not that you needed what you had :)

Code:
Dim reader As New System.IO.StreamReader
Do While reader.Read()
      TextBox1.AppendText(reader.ReadLine()
Loop
reader.Close()
 
ah..

ok know that makes some sense.. but does the reader work in the same way as VB6. I mean how do I target it so that it reads it from c:\ for example.
 
Oh sorry forgot about that :)
Code:
Dim reader As New System.IO.StreamReader("pathtofile")
Do While reader.Read()
      TextBox1.AppendText(reader.ReadLine()
Loop
reader.Close()
 
Back
Top