title: Appending a csv file
body: <pre><code>Dim NumberOfRecords As Integer
  
  Sub Main()
      Call ListTowns()
  
  End Sub
  
  Sub ListTowns()
      Dim FileName As String
      Dim MyFormat As String = "{0,  -22} {1,  -16} {2,  -8} {3,  -8}"
      FileName = "Towns.csv"
  
      Dim AllRecords As String() = System.IO.File.ReadAllLines(FileName)
  
      Dim TownList = From record In AllRecords
          Let field = record.Split(",")
              Select New With {.Name = field(0), .County = field(1), .Population = field(2), .Area = field(3)}
  
      For Each Town In TownList
          Console.WriteLine(String.Format(MyFormat, Town.Name, Town.County, Town.Population, Town.Area))
      Next
      NumberOfRecords = TownList.Count
      Console.ReadLine()
  
  End Sub
  
  Sub AddRecord()        
      Dim FileName As String
  
      FileName = "C:\Users\Omar\Desktop\Towns.csv"
      FileOpen(1, FileName, OpenMode.Random)
      Dim NewRecord As String
  
  
      Console.WriteLine("Enter the record you want add")
      NewRecord = Console.ReadLine()
      FilePut(1, NewRecord, NumberOfRecords + 1)
      FileClose(1)
      Console.WriteLine("The record has been added")
      Console.ReadLine()
  
  End Sub
  </code></pre>
  
  <p>At the moment the program can list the contents of the csv file however with regard to the <code>AddRecord()</code> Sub, when I input the data <code>Test,Test,Test,Test</code> it is adding this record to the file properly and is overwriting the first record.</p>
  
  <p>How do I fix this?</p>