You are on page 1of 18

Message Box And Input Box

Input Box
Input Box is a function that displays a message

to tell the user what to enter (called prompt).

A text box where the user can enter the data.
Have two command buttons (OK and Cancel)

that can be used to either accept or cancel the input data.


Example :

InputBox Statement
InputBox ( prompt, title )
Example : To display a text box for user to type : InputBox ("Enter your full name", "Supply Name")

Activity 1
Create a program for a user to enter the name, then display the name in a text box. Create a form named frmHello with : - A text box name Text1 - Two command buttons. Caption Input name cmdInput and Quit name cmdQuit.

Write code for Input command box :

Private Sub cmdInput_Click() 'This program allows you to enter your name 'It then displays a hello greeting, followed by your name Dim FullName As String FullName = InputBox("Enter your full name", "Supply Name") Text1.Text = "Hello" & FullName End Sub

Write code for Quit command box to close

the program.

Output :

Messages Boxes
A massage box is a special type of Visual Basic window

in which you can display a message to the user.

You can display a message, an optional icon, a title bar

caption and common button(s) in a message box.

You may want to display a message when the user has

entered invalid data or neglected to enter a required data value.


Example :

MsgBox Statement
MsgBox Message string [,ButtonType + Button Icon] [, Caption of title bar]

Example :

To display message box with button type only :

MsgBox "Welcome to Visual Basic", 1, "Welcome

To display message box with button type and button icon :

MsgBox "Welcome to Visual Basic", 1 + 64, "Welcome"

Optional Button Type Values

Type Value 0 1 Description Display OK Button only Display OK and Cancel buttons

3 4 5

Display Abort, Retry and Ignore buttons

Display Yes, No and Cancel buttons Display Yes and No buttons Display Retry and Cancel buttons

MsgBox Icons
Icon X


This critical icon is usually displayed when serious errors or problem occur.

16 32
48 64

The question mark icon is typically displayed when a user must make a decision.
The exclamation mark icon is to draw attention to the message being displayed. This icon indicates that information about an action is being displayed.


Activity 2
Create a form named frmMain with :

- A label You Are Now Working With Visual Basic 6.0 name your label as lblIntro. Write the code for Form_Load () event to display message box :


Output :


Activity 3
Create a Welcome program : Create a form named frmMain as below :




Question :
Write the code to get the output as below :


Control Dialog
Control Name Purpose Gets the drive, folder name, and file name for an existing file OpenFileDialog

Gets the drive, folder name and file name for a new file SaveFileDialog

Lets the user select a color from a palette ColorDialog

Lets the user set printing options PrintDialog

Thank You !!