1. VbScript | Message Box

Remember to try out the codes for yourself as an exercise. You lose what you don’t use, and the same can be said about knowledge.

Today we are going to talk about the MsgBox function in VbScript. It’s a useful command that allows you to communicate with the user.

Breaking it Down: Msgbox is the dialog box. “Box Message” is the content that goes in the dialog box. Type is type of box shown. “Title” is what goes in the header of the dialog box.

Syntax Note: Capitalization & Spaces don’t matter; doesn’t affect the function of the script. Remember, separate lines do affect the script.

Example:

Output:

Capture2

Example2:

Output:

Capture3

Example3:

Output:

Capture4


MsgBox Button Feedback:

Have you noticed that the dialog boxes have yes, no, abort, etc. buttons? You can set your message boxes to give feedback depending on what buttons are pressed. You can do this by storing the chosen button value in a variable, and using if-then statements.

For example:

Output:
Capture5

You get an error? What? Why, you may ask. That’s because when you are using a variable “x” you need to tell the program what the starting and ending point of the script are. You can do that by adding Parenthesis ()

Fixed Script:

Output:

Vb Script: If Then example

Notice that the Yes button has the value 6 & the No button has the value 7.


One thought to “1. VbScript | Message Box”

What's Your Opinion?