Imports System.IO Public Class frmPart3 Private Sub frmPart3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Call ReadMyFile() End Sub Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click Call ReadMyFile() End Sub Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click If Trim(txtNew.Text) <> "" Then lbItems.Items.Add(txtNew.Text) txtNew.Text = "" End If End Sub Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click Call UpdateMyFile() End Sub Private Sub ReadMyFile() Dim InBuf As Integer Dim dataFile As String '---trap any File I/O errors Try InBuf = FreeFile() FileOpen(InBuf, "a:\storeitems.txt", OpenMode.Input) Do Until EOF(InBuf) dataFile = LineInput(InBuf) 'read in an entire line using lineinput lbItems.Items.Add(dataFile) 'add the item just read into the listbox Loop FileClose(InBuf) Catch Err As IOException MessageBox.Show(Err.Message, "I cannot Read the File") Me.Close() End Finally FileClose(InBuf) End Try End Sub Private Sub UpdateMyFile() Dim OutBuf As Integer Dim x As Integer OutBuf = FreeFile() '---trap any File I/O errors Try OutBuf = FreeFile() FileOpen(OutBuf, "a:\storeitems.txt", OpenMode.Output) '---loop through the list of items in ListBox and write each item to ' the sequential file. '---count holds total number of items but is zero based ' so we subtract 1. First item in ListBox is 0 not 1 so start the loop at 0. ' Count must be less 1 because I use x to count the loop and also identify the actual item. 'If I new there we only/always 4 items, I could use For x = 0 to 3. '---EXAMPLE: ' Index Item Count ' 0 apples 1 ' 1 oranges 2 ' 2 tires 3 ' 3 boxes 4 For x = 0 To lbItems.Items.Count - 1 PrintLine(OutBuf, lbItems.Items(x)) Next FileClose(OutBuf) Catch Err As IOException MessageBox.Show(Err.Message, "I cannot access the File") Me.Close() End Finally FileClose(OutBuf) End Try End Sub End Class