We have not written any code for Exit yet. The exit button would be fairly simple, except that we would like to ask if they want to save. We would only ask this if there have been changes to the combo list. Instead of just using End for this procedure, we will give the user a chance to save if they haven’t saved since the last change. Almost every program will remind you if you didn’t save. The additions below will implement the "Save Reminder". A variable Changed will be used to keep track of whether there have been changes since the last save In order to know if there have been any changes, we need to do the following;
After adding changed, write the code for exit as shown below:
Private Sub mnuExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) _ Handles MnuExit.Click AskToSave() End Sub 'mnuExit_Click Private Sub AskToSave() Dim Answer As MsgBoxResult If Changed Then Answer = MsgBox("Do you want to save?", _ MsgBoxStyle.YesNoCancel + MsgBoxStyle.Question, "Save") If Answer = MsgBoxResult.Yes Then SaveList() End 'end the program after saving End If If Answer = MsgBoxResult.No Then End 'end the program without saving End If 'Do NOT end if they cancel! Else End 'end the program if no changes End If End Sub 'AskToSaveTest all of the options and save all of the files in the application.