How to Make, Save, and Run a Simple VBScript Program?

VBScript is a lightweight scripting version of the popular Microsoft Visual Basic, developed by as the name suggests, Microsoft. It is used to develop dynamic web pages. It is much lighter compared to Visual Basic programming language but works as a scripting language like JavaScript. To run VBScript on the client-side, the client must have to use Internet Explorer because other browsers are still not supported by the VBScript.

How to make a VBScript program?

Just like many other simple scripting languages, VBScript can be written on a simple word editor, like notepad and other such softwares (e.g. notepad++, Wordpad, etc.). Refer the following steps to get a better idea of making a VBScript program:

Step 1: Open up a word editor of your choice (Here, notepad is used).

 
Step 2: For now, here is a simple VBScript program that will make a simple message dialog box to appear on the screen. The code for such a program in VBScript is:

a = msgbox("Have a good day, fellow GFG reader!", 0, "Making a VBSript program")

Code Explanation: You can put anything as long as it follows the variable declaration rules in VBScript instead of “a” which is at the beginning of the above code. Effectively, We can break and understand the above code in the following manner:



put_any_Variable_name = msgbox("Your main text here", 0, "Your title text here")

 
To change the property of the dialog box with respect to what you need, refer the following data:



Code Property
0 Only “OK” button will be displayed.
1 OK and Cancel buttons will be displayed.
2 Abort, Retry, and Ignore buttons will be displayed.
3 Yes, No, and Cancel buttons will be displayed.
4 Yes and No buttons will be displayed.
5 Retry and Cancel buttons will be displayed.
16 Critical Message icon will be shown in the dialog box
32 Warning Query icon will be shown in the dialog box
48 Warning Message icon will be shown in the dialog box
64 Information Message icon will be shown in the dialog box
0 First button will become default
256 Second button will become default
512 Third button will become default
768 Fourth button will become default
0 Triggers the application modal (basically, the current application will stop working until the user responds to the dialog box)
4096 Triggers the System modal (basically, all applications will stop working until the user responds to the dialog box)

Change “0” in the above written code with any of the numbers provided just above. 
To get more than one above mentioned property in you dialog box, you can simple write, for example: “0+16”, instead of “0” in above code. 
For reference, the code:

hydro = msgbox("Remeber to drink water!", 0+64, "Hydration Check")

will give the following output:

That’s it, we have just written a basic VBScript program that will display a dialog box as output. Now onto saving this program.

How to save a VBScript program?

Follow the steps given below to save a VBScript program:

Step 1: Press Ctrl + Shift + S on the keyboard, Or click File>Save As on the notepad window, this will open up a Save As dialog window asking where to save the current notepad document.

 
Step 2: Now write any file name of your choice for this notepad document but make sure you write .vbs as its extension. Make sure to add “.vbs” after writing the file name in the “File name:” field.

 
Step 3: Now, change the value of “Save as type:” field from “Text Documents (*.txt)” to “All Files (*.*)” by clicking on it with help of the drop down menu.

 
Step 4: Finally, click on save after choosing an appropriate location of where the file should be saved to.

How to run a VBScript program?

Now, this is a very simple thing to do, simply double click on the now saved .vbs file from wherever you saved it and voila! It will run and give you the following output:

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.