How to Write a General VBScript

by Contributor

Microsoft developed the VBScript scripting language. You can use this language to write functions that run on Web pages browsed in Internet Explorer pages in much the same way that JavaScript is used. In addition, VBScripts can run automatic applications on servers and computers. The great thing about VBScripts is once you understand how to write them, you can use this understanding to write scripts in other programming languages as well.


Open Notepad or your preferred text editor. You can use this application to write and edit your VBScript.


Start your script with the following code on its own line: Option Explicit


Declare your variables directly under the Option Explicit line. You do this by using the DIM command. A variable is basically a nickname for a specific data value stored and accessed by your script.


Leave one blank line and then begin the Reference section of the script. In this section, you assign values to the variables you created previously. Simply declare the variable, follow it with an equal sign and then type the value you wish to assign to it.


Leave another blank line and begin the Worker section of the script. This section is where the variables and references from the preceding steps actually do something. The Set command is commonly found in this section of the script.


Leave a blank line and begin the Output section of the script. This is where the script echoes results to the user or to a log file. The "WScript.Echo" command will come into play here.


Save your script and give it a ".vbs" file extension. Once saved, you can run the script in several ways. One option is to simply double-click on the file. Another option is to use the CScript function at the command prompt. Alternately, you can drag and drop the file into Command prompt or you can run it through Visual Studio to check for errors.


  • check Browse websites where VBScript is discussed for scripting ideas and tutorials.
  • check If you do not want to run the script but you want to check it for accuracy, use the Microsoft Visual Studio.Net program.


  • close If you are not proficient at writing VBScript code, be careful when you write code designed to alter files or setting on your computer.

Items you will need

More Articles

Photo Credits

  • photo_camera Thinkstock Images/Comstock/Getty Images