title: Visual Basic - Not Overwriting a Text File
body: <p>I am writing a program where the user will be given a score and a name, and the two need to be saved in memory, then to be displayed in a listbox. Example:
  Peter Paul 2000</p>
  
  <p>With this in mind, the data cannot be overwritten. Example:
  Peter Paul 2000
  Peter John 195
  Peter Jack 2301
  Peter Best 7841</p>
  
  <p>And then displayed from Highest to smallest. </p>
  
  <p>Any Ideas? </p>
  
  <p>Current Coded used in program to write and read the file:</p>
  
  <pre><code>Private Sub OpenButton_Click(sender As Object, e As EventArgs) Handles OpenButton.Click
      Dim CountInteger As Integer
      Dim InStreamReader As New StreamReader("LeaderBoard.txt", False)
      ScoreListBox.Items.Clear()
      Do Until InStreamReader.Peek = -1
          InStreamReader.ReadLine()
          CountInteger += 1
      Loop
      InStreamReader.Close()
      CountInteger -= 1 'need ubound not size
      Dim InNewStreamReader As New StreamReader("LeaderBoard.txt", False)
      Dim DataArray(CountInteger) As String
      For i As Integer = 0 To UBound(DataArray)
          DataArray(i) = InNewStreamReader.ReadLine()
          ScoreListBox.Items.Add(DataArray(i))
      Next
      InNewStreamReader.Close()
  End Sub
  
  Private Sub SaveButton_Click(sender As Object, e As EventArgs) Handles SaveButton.Click
      Dim ResultDialogResult As DialogResult
      Dim LineString As String
      Dim InStreamReader As StreamReader
      Dim OutStreamWriter As StreamWriter
  
      With SaveFileDialog1
          .InitialDirectory = Application.StartupPath
          ResultDialogResult = .ShowDialog
          If ResultDialogResult = Windows.Forms.DialogResult.Cancel Then
              Exit Sub
          End If
          OutStreamWriter = New StreamWriter(.FileName)
      End With
  
  
      With OpenFileDialog1
          .DefaultExt = "txt"
          .Filter = "Text documents (*.txt)|*.txt"
          ResultDialogResult = .ShowDialog
          InStreamReader = New StreamReader(.FileName)
          Do Until InStreamReader.Peek = -1
              LineString = InStreamReader.ReadLine
              OutStreamWriter.WriteLine(LineString)
          Loop
          InStreamReader.Close()
          OutStreamWriter.Close()
      End With
  End Sub
  </code></pre>