School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,014 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,049 people online right now. Registration is fast and FREE... Join Now!




Understanding Message Boxes

 
Reply to this topicStart new topic

> Understanding Message Boxes

firebolt
Group Icon



post 14 Aug, 2009 - 07:06 PM
Post #1


Understanding Message Boxes (similarly Understanding Input Boxes)

To use a message box, you will need to know how it all works, how everything is put together. Message boxes are useful and are needed for things like if the program asks the user for a Question, the program delivers a Error Message and wants the user to know, expressing certain Conditions and much more.

Basically, you need to follow this syntax:
MsgBox(prompt[, buttons] [, title] [, helpfile, context])

If you want to call on the message box to do something, this must be used:
memory_variable = MsgBox ( prompt [, icons+ buttons] [,title] )

Each part of the Syntax is explained:
prompt
This is required as it is a string expression displayed as the message in the dialog box. This could be a warning, question or just a message for users to know.

buttons
This is an optional thing to include with your message box. Basically, this is a numeric expression that is the sum of values specifying the number and type of button/s to display. As this is optional, if this is omitted, it is set to its default (0) which causes only an OK button to be displayed. You may use either the worded syntax, or the assigned number.

title
This is the title of the message box which is going to be displayed. This is optional and if omitted, a default name will be used.

helpfile and context
These arguments are only applicable when a Help file has been set up to work with the application and therefore these are optional.

- - - - - - -
A simple example to use is:
CODE

MsgBox "Hello there!"

When this is used under the Form_Load event, the most basic of all message boxes will appear, expressing the message "Hello there!".

We can expand on our first example and use the memory_variable:
CODE

Dim Response As Integer
Response = MsgBox("Is this a great tutorial?", vbYesNo)
If Response = vbYes Then
    MsgBox("Thank You!")
Else
    MsgBox("ORLYNAO?")
End If

This would be a message box appearing, with a Yes and No buttons and if the user selects the first button, Yes, another message box will appear saying "Thank you!". If the second button is clicked, a message box will appear saying "ORLYNAO?". tongue.gif

Obviously, we can expand even more. We can add features and extra emphasis on the message. We can add a button like so:
CODE

MsgBox "The floor is wet!", vbExclamation + vbOKOnly, "Caution"

Simply, an Exclamation icon will appear. The vbExclamation can be replaced with other variables, listed below.

And we can make a button a default when the message box pops up:
CODE

Dim Response As Integer
Response = MsgBox("Do you really like this tutorial?", vbYesNo + vbQuestion + vbDefaultButton1, "Question?")
If Response = vbYes Then
    MsgBox “YAY!!!”
Else
    MsgBox “Mhmmm...”
End If

The first button will be the default in this can. Like before, it can be changed.

- - - - - - -
Attached - Table of buttons and icons:
Attached Image

-Firebolt-

This post has been edited by firebolt: 14 Aug, 2009 - 10:22 PM
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 


Lo-Fi Version Time is now: 11/21/09 07:25AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month