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:
You can add different types of Box formats together with a + sign:
MsgBox"Joker's got Batman",vbAbortRetryIgnore + vbExclamation,"hello"
Compounding VbType Attributes
Another example of using + to compound vbtypes into 1 box:
MsgBox"Joker's got Batman",vbAbortRetryIgnore+vbExclamation+vbDefaultButton2,"hello"
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"
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
For your reference, here is a list of vbtype code phrases you can use:
2 thoughts to “2. VbScript | Message Box: Constants”
What do you mean by value listed in the box above?
Which Value? Be specific so I can help! :)