Files in Visual Basic

Write the contents of the combo box to a file

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
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
  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
 End Sub 'mnuDelete_Click

Private Sub DeleteItem()
   If Me.CboTodo.Items.Count > 0 Then
      Me.CboTodo.Text = ""
    End If
    If Me.CboTodo.Items.Count > 0 Then
       Me.CboTodo.SelectedIndex = 0
    End If
End Sub 'DeleteItem
Make sure that you can add, delete, and save before you go on.

NEXT: Do you want to save?