Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am using the following code:

 

Dim rdBfr As New System.IO.StreamReader(dlgO.FileName)
               Do While rdBfr.Read()
                   txtOriginal.Text = txtOriginal.Text & rdBfr.ReadLine()
               Loop
               rdBfr.Close()

 

However, the aplication crashes when I use it. What is the problem?

  • Leaders
Posted

and you may not need to use Do While , rather you can use While Not rdBfr.Peak() , here's a quick example :

       Dim dlgO As New OpenFileDialog()
       With dlgO
           .Filter = "text|*.txt"
           .InitialDirectory = "D:\"
           If .ShowDialog = DialogResult.OK Then
               Dim rdBfr As New IO.StreamReader(New IO.FileStream(dlgO.FileName, IO.FileMode.Open))
               While Not rdBfr.Peek '/// make sure it only reads till it gets to it's peak.
                   txtOriginal.AppendText(rdBfr.ReadLine & Environment.NewLine)
               End While
           End If
       End With

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...