VB Message Box

Visual Basic Message Box
VB provides a means for creating interractive applications enabling the program to communicate to the user via the user interface. This is done by means of displaying appropriate message boxes. Syntax: MsgBox ( Prompt [,icons+buttons ] [,title ] ) memory_variable = MsgBox ( prompt [, icons+ buttons] [,title] ) Prompt : This is a string expression displayed as the message in the dialog box. If prompt consist of more than one line, then you can separate the lines using the vbrCrLf constant.

Icons + Buttons : Numeric expression that is the sum of values specifying the number and type of buttons and icon to display.

Title : This is a string expression displayed in the title bar (caption) of the dialog box. If you omit title, then the applications name is placed in the title bar of the message box by default.

Message Box Icons:
These are the different types of Message Box displays available in VB. These can be obtained by specifying the type of Message Box icon within the Message Box statement.

Message Box Buttons
These are the different types of buttons that can be displayed in a Message Box, when specified in a Message Box statement, they define or determine the type of button(s) to be displayed by that Message Box.

Return Values
When an action is performed on a Message Box button, a corresponding value is returned to the program (application). The value returned determines the programs next course of action. There are several Visual Basic return values. These are listed in the table below. Below is an example illustrating the use of (different types of) Message Boxes messageboxexample.vbp The code in the txtStudName_Change event procedure: Private Sub txtStudName_Change If Len(txtStudName.Text) > 0 Then cmdAdd.Enabled = True End If End Sub The code for the cmdAdd_Click event procedure: Private Sub cmdAdd_Click answer = MsgBox("Do you want to add this name to the list box?", vbExclamation + vbYesNo,  "Add Confirm") If answer = vbYes Then lstStudName.AddItem txtStudName.Text txtStudName.Text = "" txtStudName.SetFocus cmdAdd.Enabled = False End If End Sub The code in the cmdDelete_Click event procedure: Private Sub cmdDelete_Click Dim remove As Integer remove = lstStudName.ListIndex If remove < 0 Then MsgBox "No names is selected", vbInformation, "Error" Else answer = MsgBox("Are you sure you want to delete " & vbCrLf & "the selected name?",_     vbCritical + vbYesNo, "Warning") If answer = vbYes Then If remove >= 0 Then lstStudName.RemoveItem remove txtStudName.SetFocus MsgBox "Selected name was deleted", vbInformation, "Delete Confirm" End If   End If    End If  End Sub The code in the cmdExit_Click event procedure: Private Sub cmdExit_Click answer = MsgBox("Do you want to quit?", vbExclamation + vbYesNo, "Confirm") If answer = vbYes Then End Else MsgBox "Action canceled", vbInformation, "Confirm" End If End Sub
 * Open a new Project and save the Form as messageboxexample.frm and save the Project as
 * Then you can design the applications interface as shown below (or choose your own format).