title: Writing Entries in a VB Dictionary into a Text File
body: <p>I'm working on VB in college and am running into a snag with one of my assignments.  Can someone help?  I'm aiming to try to take the following dictionary code:</p>
  
  <pre><code>Public Class Inventory
  Public ItemInventory As New Dictionary(Of String, Item)
  
  Public Function iItem(ByVal key As String) As Item
      Return ItemInventory(key)
  End Function
  
  Public Sub addItem(ByVal item As String, ByVal Desc As String, ByVal DRate As Double, ByVal WRate As Double, _
                     ByVal MRate As Double, ByVal Quantity As Integer)
      With ItemInventory
          .Add(item, New Item(item, Desc, DRate, WRate, MRate, Quantity))
      End With
  End Sub
  
  Public Sub removeItem(ByVal item As String)
  
      With ItemInventory
          .Remove(item)
      End With
  End Sub
  
  Public Function returnKeys() As String()
      Dim Keys() As String
  
      With ItemInventory
          Keys = .Keys.ToList.ToArray
      End With
  
      Return Keys
  End Function
  End Class
  </code></pre>
  
  <p>Not pretty, I know, but it gets the job done, that's all I aim to do.  Now a bit of this also has to do with displaying a dictionary item in the program, which I'm also having issues with, however, I'd like to take this one step at a time, so we'll get to that later, if possible.</p>
  
  <p>As per writing, this is my current code for reading and writing:</p>
  
  <pre><code>    Imports System.IO
  
  Public Class InventoryFile
      Public Sub RFile(ByVal FPath As String, ByRef dInventory As Inventory)
          Dim infile As StreamReader = File.OpenText(FPath)
          Dim entireLine As String = infile.ReadLine()
          Dim fields() As String = entireLine.Split(","c)
  
          While infile.EndOfStream
              Dim dItem As New Item
              dItem.ID = fields(0)
              dItem.Description = fields(1)
              dItem.Daily = fields(2)
              dItem.Weekly = fields(3)
              dItem.Monthly = fields(4)
              dItem.Quantity = fields(5)
  
              'AddItem
              dInventory.addItem(dItem.ID, dItem.Description, dItem.Daily, dItem.Weekly, _
                                 dItem.Monthly, dItem.Quantity)
  
          End While
      End Sub
  
      Public Sub WFile(ByVal FPath As String, ByRef dInventory As Inventory)
          Dim outfile As StreamWriter = File.CreateText(FPath)
  
          For Each Item As KeyValuePair(Of String, Item) In dInventory.ItemInventory
  
  
  
          Next
      End Sub
  
  
  End Class
  </code></pre>
  
  <p>I hope that posted right.  Now, reading in, as far as I understand, works just fine, in terms of a file going into a dictionary, however 'WFile', my StreamWriter, is what's got me stumped.  Can someone help me with that?  Likewise, its supposed to close and write to the file upon closing, and my only code for the close button is the Me.Close() command.  How would I write a trigger to make the program write to the file?  Know that the main form code, and my 'InventoryFile' are both separate classes, so this has to be done by referencing the other classes in question</p>