Simple message boxes can be made to pop up with information for the user by use of the msgBox command.

For example, this line:
MsgBox "Have a nice day!", , "Greeting"

would produce this message box:

You can also add icons to catch the user's attention by putting a number between the message and the title bar text

Critical Message

MsgBox "Have a nice day!", 16, "Greeting"

Warning Query

MsgBox "Have a nice day!", 32, "Greeting"

Warning Message

MsgBox "Have a nice day!", 48, "Greeting"

Information Message

MsgBox "Have a nice day!", 64, "Greeting"

 

Visual Basic only allows you to display the 4 icons shown above in a message box, but if you want more, you can always design your own dialogue box from scratch.  To do this, create a separate form, set the form's BorderStyle property to  fixed dialogue and draw command buttons and an image box directly on to the form.  You can then load any type of icon you want.

Input Boxes

An InputBox( ) function will display a message box where the user can enter a value or a message in the form of text. The user's input is stored in a variable.  The format is

variable = InputBox("Prompt", "Title")

So for example,  userName = InputBox("What is your name?", "Title") would pop up this input box

Whatever the user types would be stored in the variable called userName.


We will create a simple application that asks the user's name, then responds to them:

Set up an interface like this: 

Write the code:

Private Sub cmdGreeting_Click()
     Dim userName As String
     userName = InputBox("What is your name?", "Greeting")
     MsgBox "Hello " & userName, 64, "Greeting"
End Sub

The input box line stores the user's name in the variable called userName

The message box line uses the & operator to join the word 'Hello' to whatever is stored in userName

 
MsgBox "Hello " & userName would give this output:

MsgBox "Hello & userName" would give this output:

Modify any one of the previous activities so that it greets the user when they start it.