'Programmer: Janet Joy 'List manager program with menu Public Class Form1 Dim currentFile As String Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles mnuExit.Click 'Temporary: we will addcheck for save later End End Sub Private Sub mnuInsert_Click(sender As Object, e As EventArgs) Handles mnuInsert.Click 'Add an item to the list box Dim s As String s = InputBox("Enter item", "Add Item") If s <> "" Then ListBox1.Items.Add(s) End If End Sub Private Sub mnuDelete_Click(sender As Object, e As EventArgs) Handles mnuDelete.Click 'Delete if there are items and one is selected If ListBox1.Items.Count > 0 And ListBox1.SelectedIndex >= 0 Then ListBox1.Items.RemoveAt(ListBox1.SelectedIndex) Else ListBox1.Text = "" End If If ListBox1.Items.Count > 0 Then ListBox1.SelectedIndex = 0 End If End Sub Private Sub SaveList() Dim S As String Dim Num As Integer If currentFile = "" Then SaveFileDialog1.ShowDialog() currentFile = SaveFileDialog1.FileName End If If currentFile <> "" Then FileOpen(1, currentFile, OpenMode.Output) For Num = 0 To ListBox1.Items.Count - 1 S = ListBox1.Items.Item(Num) PrintLine(1, S) Next Num FileClose(1) MsgBox("Items saved: " & ListBox1.Items.Count) End If End Sub 'SaveList Private Sub mnuSave_Click(sender As Object, e As EventArgs) Handles mnuSave.Click SaveList() End Sub Private Sub mnuOpen_Click(sender As Object, e As EventArgs) Handles mnuOpen.Click 'Opens selected file and adds to list box If OpenFileDialog1.ShowDialog() = DialogResult.OK Then currentFile = OpenFileDialog1.FileName Dim S As String = "" Me.Text = currentFile ListBox1.Items.Clear() 'remove everything from previous list FileOpen(1, currentFile, OpenMode.Input) 'open the file for input While Not EOF(1) 'EOF=End of file, this loops to read all lines in the file S = LineInput(1) 'read from file 1 Me.ListBox1.Items.Add(S) 'add the item read to the combo box End While FileClose(1) 'close file 1 If Me.ListBox1.Items.Count > 0 Then 'make sure the file was read Me.ListBox1.SelectedIndex = 0 'select the first itme End If End If End Sub End Class