You can use the following code with creating an Exit Command Button or Menu item.
'Exit and close the form If MessageBox.Show("Are you sure you want to exit the program?", _ "Exit Warning", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then Me.Close() End If
Note: the If statement is broken into two lines in order to fit on the screen. The _ tells Visual Basic that the second line of code is a continuation of the top line.