Compare the code to save the file to the one to read it.
Private Sub MnuSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) _ Handles MnuSave.Click SaveList() End Sub 'mnuSave_Click Private Sub SaveList() Dim S As String Dim Num As Integer FileOpen(1, "C:\todo.txt", OpenMode.Output) For Num = 0 To Me.CboTodo.Items.Count - 1 S = Me.CboTodo.Items.Item(Num) PrintLine(1, S) Next Num FileClose(1) MsgBox("Items saved: " & Me.CboTodo.Items.Count) End Sub 'SaveList
You should make sure that you can add and save before you go on.
Deleting takes a little extra work because we have to make sure that we don’t try to delete after the list is already empty. After an item is deleted, we would like to display the first item. Again, we can’t display the first item if we have just deleted the last item.
Private Sub mnuDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) _ Handles MnuDelete.Click DeleteItem() End Sub 'mnuDelete_Click Private Sub DeleteItem() If Me.CboTodo.Items.Count > 0 Then Me.CboTodo.Items.RemoveAt(Me.CboTodo.SelectedIndex) Else Me.CboTodo.Text = "" End If If Me.CboTodo.Items.Count > 0 Then Me.CboTodo.SelectedIndex = 0 End If End Sub 'DeleteItemMake sure that you can add, delete, and save before you go on.