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.
Msgbox "Box Message",Type,"Title"
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.
MsgBox "Box message",0,"title"
MsgBox "Bannana Smoothie",20,"Hello"
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.
x = MsgBox "Would you like a Shotgun Smoothie?",36,"hello" If x=6 then msgbox "Bam!!!"
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 ()
x = MsgBox("Would you like a Shotgun Smoothie?",36,"hello") If x=6 then msgbox "Bam!!!",64 If x=7 then msgbox "Too bad, I'll just have one myself",16
Notice that the Yes button has the value 6 & the No button has the value 7.