How to Write a General VBScript

by eHow 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.

1

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

2

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

Option Explicit

3

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.

4

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.

5

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.

6

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.

7

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.

Tips

  • 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.

Warning

  • 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

About the Author

This article was created by a professional writer and edited by experienced copy editors, both qualified members of the Demand Media Studios community. All articles go through an editorial process that includes subject matter guidelines, plagiarism review, fact-checking, and other steps in an effort to provide reliable information.

Photo Credits

  • photo_camera Thinkstock Images/Comstock/Getty Images