Guide:Visual Basic Message Boxes

Most guides on creating message boxes with Visual Basic (except for Microsoft Docs' version) refer to outdated versions of Windows. This guide will focus on the Windows 10 operating system, combining information from various sources.

A note about the examples: The examples featured here are designed to be a reference. You are welcome to use these examples as a start to your own Visual Basic programs.

What is Visual Basic?
Visual Basic is a coding language, like JavaScript and BASIC. The file extension for these program files is .vbs, which is a Visual Basic Script file. There are two ways to execute a VBS file: the first is by double-clicking the file, assuming the default program to open these files is Microsoft Windows Based Script Host. The second is by executing the file in Command Prompt. To do that, type in this command: and replace "filename.vbs" with the script file. Remember, you can precede the file name with the directory the file is located. For example, to execute the script file named "Messagebox.vbs", located in "C:\Users\Test\Desktop\Folder", you would type in this command: VBS files can be edited with a text editor or a word processor (as long as you save it unformatted/without formatting codes). I recommend using Notepad or this online text editor which supports opening of various files, including VBS files. Most of the commands used in VBS files may be unfamiliar to you, but luckily, Microsoft has documents about the commands for Visual Basic files, which can be viewed by clicking here. For now, we will just take a look at a few that are used for this guide, which I'll save for later.

Starting to Code
Open a new file in the text editor or word processor of your choice. (If using a word processor, make sure to save the file without formatting codes.) Type in the following code into the blank document: Don't worry about anything that is unfamiliar to you, as I will explain it to you later. For now, save the file as "FirstProgram.vbs" and run the program.

Did it work?
If you see an error message on your screen, the code is not correct. Edit the file, and make sure the code is the same as the one on this page. If you see a message box saying "This is a test message.", then Congrats, you have created your first Visual Basic Program! It's not much, but does showcase what you can do with this coding language.

The Commands You Used
Now I'll talk about the commands used in this batch file.

The "Dim" Command
The "Dim" command initializes variables for use with the program. Multiple names of variables can be put in this command, as long as you separate the names with a comma.

Setting Variables
Using the equals sign between a variable name and a value (a command, a number or another variable) allows the program to set the value of the variable before the equals sign to the value of the item that is after the equals sign.

The "MsgBox" Command
The main part of the VBS file you created is the "MsgBox" command. The command creates a message box on the screen.