Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I rearranged your code just a bit. Basically you were creating a stream, and then creating the reader for the stream to "messages.txt". Later you set the <code>stream</code> object to a new stream based on the <code>OpenFile</code> method of the file open dialog. But your reader was still pointing to the first stream you opened, so that is what was getting read. I've changed the code below to not open that first stream, and to create the reader after you have created the stream based on the file the user selected.</p> <pre><code>'don't create a stream hear and the reader, because you are just recreating a stream later in the code Dim Stream As System.IO.FileStream Dim Index As Integer = 0 Dim openFileDialog1 As New OpenFileDialog() openFileDialog1.InitialDirectory = "D:\work" openFileDialog1.Filter = "txt files (*.txt)|*.txt" openFileDialog1.FilterIndex = 2 openFileDialog1.RestoreDirectory = True If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then Try 'This line opens the file the user selected and sets the stream object Stream = openFileDialog1.OpenFile() If (Stream IsNot Nothing) Then 'create the reader here and use the stream you got from the file open dialog Dim sReader As New System.IO.StreamReader(Stream) Do While sReader.Peek &gt;= 0 ReDim Preserve eArray(Index) eArray(Index) = sReader.ReadLine RichTextBox3.Text = eArray(Index) Index += 1 Delay(2) Loop End If Catch Ex As Exception MessageBox.Show(Ex.Message) Finally If (Stream IsNot Nothing) Then Stream.Close() End If End Try End If End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload