2. VbScript | Message Box: Constants

Remember to follow along by trying the codes here yourself! Use or lose it, as they say.

Table of Contents

Dialog Box Format

So before we talked about the basic format that can be used for making dialog boxes:

x=msgbox(“box message” ,vbtype, “box title”)
&
msgbox “box message” ,vbtype, “box title”

Message Box Constants

In this lesson we are going to talk about manipulating the constant portion of the code, or vbtype. Numbers don’t tell you directly the kind of box you are going to make, and is hard to memorize. For example:

MsgBox"Joker's got Batman",2,"hello"

Instead of numbers, we can use English phrases to make it more memorable.

MsgBox"Joker's got Batman",vbAbortRetryIgnore,"hello"

Both 2 & vbAbortRetryIgnore output the same box type:
Capture6

You can add different types of Box formats together with a + sign:

MsgBox"Joker's got Batman",vbAbortRetryIgnore + vbExclamation,"hello"

Output:

#####Capture


Compounding VbType Attributes

Another example of using + to compound vbtypes into 1 box:

MsgBox"Joker's got Batman",vbAbortRetryIgnore+vbExclamation+vbDefaultButton2,"hello"

Output:

#######Capture

What vbDefaultButton2 does is keep the selected button defaulted to the 2nd button, You’ll notice the 2nd button is selected in the picture above. So this function is useful if you want your users to normally click a specific button over the other ones.


Keeping Dialog Box On Top

Now if you want to keep you dialog box always on-top of everything, you can use vbSystemModal:

MsgBox"Joker's got Batman",vbAbortRetryIgnore+vbExclamation+
_vbDefaultButton2+vbSystemModal,"hello"

Output:

Remember that the underscore _ allows you to continue the statement on the next line.


Another MsgBox Feedback Example:

a=MsgBox("Joker's got Batman",vbAbortRetryIgnore+vbExclamation+vbDefaultButton2+vbSystemModal,"hello")
If a=vbAbort then msgbox "quit",vbcritical

Output:


For your reference, here is a list of vbtype code phrases you can use:
vbscript_msgbox_chart


2 thoughts to “2. VbScript | Message Box: Constants”

What's Your Opinion?