PDF download Download Article PDF download Download Article

VBScript is a Windows-native programming language that is mainly used to create web server applications. VBScript is embedded within an HTML file, and is fairly straightforward. Note that VBScript differs from Visual Basic, which is used for desktop programming.

Part 1
Part 1 of 5:

Setting Up Your Development Environment

PDF download Download Article
  1. You can use Notepad, but a more robust editor will make it easier to see the syntax of your VBScript code.
  2. Internet Explorer is the only browser that supports VBScript, as it is a proprietary Microsoft product. You will need Internet Explorer installed in order to see your VBScript in action.
    • Since Internet Explorer is only supported on Windows, you will have the best results if you program on a Windows computer.
    Advertisement
  3. There are several important basics that it will be helpful to know before you dive too deep into coding.
    • Use ' (apostrophe) to designate a comment. Any line that starts with an apostrophe is designated as a comment and is not processed by the script. Use comments often to help other developers, and yourself, figure out what the code is doing.
    • Use _ (underscore) to extend the end of a line. The end of a line of code is typically designated by simply moving to the next line, but if the line becomes very long and needs to wrap to the next line, place a _ at the end of the unfinished line to indicate that the line continues on the next line.
  4. Advertisement
Part 2
Part 2 of 5:

Creating a Base Page

PDF download Download Article
  1. VBScript exists within HTML websites. In order to see your VBScript working, you will need to create an HTML file that you can open in Internet Explorer.
    • If you have IE version 11 or higher, you need to switch on emulation for IE10 because IE11 does not support VBscript by default. If so, add this tag to the top of your vbscript code: <meta http-equiv="x-ua-compatible" content="IE=10">
    • Open your code editor and enter the following:
       < 
       html 
       > 
       < 
       head 
       > 
       < 
       title 
       > 
      VBScript Test </ 
       title 
       > 
       </ 
       head 
       > 
       < 
       body 
       > 
       </ 
       body 
       > 
       </ 
       html 
       > 
      
  2. When creating a webpage with VBScript, you need to let the browser know that the script is coming up. Insert the tag into your HTML source:
     < 
     html 
     > 
     < 
     head 
     > 
     < 
     title 
     > 
    VBScript Test </ 
     title 
     > 
     </ 
     head 
     > 
     < 
     body 
     > 
     < 
     script 
     language 
     = 
     "vbscript" 
     type 
     = 
     "text/vbscript" 
     > 
     </ 
     script 
     > 
     </ 
     body 
     > 
     </ 
     html 
     > 
    
  3. If you are writing VBScript for an ASP server, you can indicate that the script is starting by using a special tag:
     < 
     html 
     > 
     < 
     head 
     > 
     < 
     title 
     > 
    VBScript Test </ 
     title 
     > 
     </ 
     head 
     > 
     < 
     body 
     > 
     < 
    %
    
    %> </ 
     body 
     > 
     </ 
     html 
     > 
    
  4. Advertisement
Part 3
Part 3 of 5:

Creating a "Hello World!" Program

PDF download Download Article
  1. This command is what displays content to the user. When using the write command, the designated text will be displayed in the browser.
     < 
     html 
     > 
     < 
     head 
     > 
     < 
     title 
     > 
    VBScript Test </ 
     title 
     > 
     </ 
     head 
     > 
     < 
     body 
     > 
     < 
     script 
     language 
     = 
     "vbscript" 
     type 
     = 
     "text/vbscript" 
     > 
     document 
     . 
     write 
     () 
     </ 
     script 
     > 
     </ 
     body 
     > 
     </ 
     html 
     > 
    
  2. In the parentheses, add the text that you want to be displayed on the screen. Enclose the text with quotation marks to designate it as a string.
     < 
     html 
     > 
     < 
     head 
     > 
     < 
     title 
     > 
    VBScript Test </ 
     title 
     > 
     </ 
     head 
     > 
     < 
     body 
     > 
     < 
     script 
     language 
     = 
     "vbscript" 
     type 
     = 
     "text/vbscript" 
     > 
     document 
     . 
     write 
     ( 
     "Hello World!" 
     ) 
     </ 
     script 
     > 
     </ 
     body 
     > 
     </ 
     html 
     > 
    
  3. Save your code as an .HTML file. Open the saved file using Internet Explorer. The page should display Hello World! in plain text.
  4. Advertisement
Part 4
Part 4 of 5:

Using Variables

PDF download Download Article
  1. Variables allow you to store data to be called upon and manipulated later. You need to declare variables using dim before assigning values to them. You can declare multiple variables at once. Variables must start with a letter, and can be up to 255 characters long. Below, we are creating the variable "age":
     < 
     html 
     > 
     < 
     head 
     > 
     < 
     title 
     > 
    VBScript Test </ 
     title 
     > 
     </ 
     head 
     > 
     < 
     body 
     > 
     < 
     script 
     language 
     = 
     "vbscript" 
     type 
     = 
     "text/vbscript" 
     > 
     dim 
     age 
     </ 
     script 
     > 
     </ 
     body 
     > 
     </ 
     html 
     > 
    
  2. Now that the variable has been declared, you can assign a value to it. Use the = sign to set the variable's value. You can use the Write command to display the variable on the screen to ensure everything is working
     < 
     html 
     > 
     < 
     head 
     > 
     < 
     title 
     > 
    VBScript Test </ 
     title 
     > 
     </ 
     head 
     > 
     < 
     body 
     > 
     < 
     script 
     language 
     = 
     "vbscript" 
     type 
     = 
     "text/vbscript" 
     > 
     dim 
     age 
     age 
     = 
     30 
     document 
     . 
     write 
     ( 
     age 
     ) 
     </ 
     script 
     > 
     </ 
     body 
     > 
     </ 
     html 
     > 
    
  3. You can use mathematical expressions to manipulate your variables. These expressions work much like basic algebra. All of your variables, including the answer, must be declared before using them.
     < 
     html 
     > 
     < 
     head 
     > 
     < 
     title 
     > 
    VBScript Test </ 
     title 
     > 
     </ 
     head 
     > 
     < 
     body 
     > 
     < 
     script 
     language 
     = 
     "vbscript" 
     type 
     = 
     "text/vbscript" 
     > 
     dim 
     x 
     dim 
     y 
     dim 
     sum 
     x 
     = 
     10 
     y 
     = 
     5 
     sum 
     = 
     x 
     + 
     y 
     document 
     . 
     write 
     ( 
     sum 
     ) 
     ' 
     the 
     page 
     will 
     display 
     "15" 
     </ 
     script 
     > 
     </ 
     body 
     > 
     </ 
     html 
     > 
    
  4. An array is essentially a table that can contain more than one value. The array is then treated as a single variable. Like variables, the array needs to be declared first. You must also indicate the number of values that the array can store (including 0 as the first number). You can then call on the data stored in the array later.
     < 
     html 
     > 
     < 
     head 
     > 
     < 
     title 
     > 
    VBScript Test </ 
     title 
     > 
     </ 
     head 
     > 
     < 
     body 
     > 
     < 
     script 
     language 
     = 
     "vbscript" 
     type 
     = 
     "text/vbscript" 
     > 
     Dim 
     names 
     ( 
     2 
     ) 
     Dim 
     mother 
     names 
     ( 
     0 
     ) 
     = 
     "John" 
     names 
     ( 
     1 
     ) 
     = 
     "Jane" 
     names 
     ( 
     2 
     ) 
     = 
     "Pat" 
     mother 
     = 
     names 
     ( 
     1 
     ) 
     </ 
     script 
     > 
     </ 
     body 
     > 
     </ 
     html 
     > 
    
  5. You can create an array with multiple dimensions to store more data. When declaring the array, you will indicate the number of rows and columns contained in the array.
     < 
     html 
     > 
     < 
     head 
     > 
     < 
     title 
     > 
    VBScript Test </ 
     title 
     > 
     </ 
     head 
     > 
     < 
     body 
     > 
     < 
     script 
     language 
     = 
     "vbscript" 
     type 
     = 
     "text/vbscript" 
     > 
     Dim 
     table 
     ( 
     2 
     , 
     2 
     ) 
     ' 
     This 
     will 
     create 
     a 
     3 
     x3 
     table 
     table 
     ( 
     0 
     , 
     0 
     ) 
     = 
     "A" 
     table 
     ( 
     0 
     , 
     1 
     ) 
     = 
     "B" 
     table 
     ( 
     0 
     , 
     2 
     ) 
     = 
     "C" 
     table 
     ( 
     1 
     , 
     0 
     ) 
     = 
     "D" 
     table 
     ( 
     1 
     , 
     1 
     ) 
     = 
     "E" 
     table 
     ( 
     1 
     , 
     2 
     ) 
     = 
     "F" 
     table 
     ( 
     2 
     , 
     0 
     ) 
     = 
     "G" 
     table 
     ( 
     2 
     , 
     1 
     ) 
     = 
     "H" 
     table 
     ( 
     2 
     , 
     2 
     ) 
     = 
     "I" 
     </ 
     script 
     > 
     </ 
     body 
     > 
     </ 
     html 
     > 
    
  6. Advertisement
Part 5
Part 5 of 5:

Using Procedures

PDF download Download Article
  1. There are two types of procedures in VBScript: sub and function. These two types of procedures allow your program to perform actions.
    • Sub procedures can perform actions, but cannot return a value to the program.
    • Function procedures can call other procedures as well as return values.
  2. You can use sub procedures to create tasks that your program can all on later. Use the Sub and End Sub statements to enclose the sub procedure. Use the Call statement to activate the sub procedure
     < 
     html 
     > 
     < 
     head 
     > 
     < 
     title 
     > 
    VBScript Test </ 
     title 
     > 
     </ 
     head 
     > 
     < 
     body 
     > 
     < 
     script 
     language 
     = 
     "vbscript" 
     type 
     = 
     "text/vbscript" 
     > 
     Sub 
     mysubproc 
     () 
     document 
     . 
     write 
     ( 
     "This was written in a sub procedure" 
     ) 
     End 
     Sub 
     Call 
     mysubproc 
     () 
     ' 
     This 
     will 
     display 
     the 
     message 
     written 
     in 
     the 
     sub 
     procedure 
     </ 
     script 
     > 
     </ 
     body 
     > 
     </ 
     html 
     > 
    
  3. A function procedure allows you to perform commands and return values to the program. Function procedures are where the meat of your programs functionality will occur. Use the Function and End Function statements to designate the contents of the function.
     < 
     html 
     > 
     < 
     head 
     > 
     < 
     title 
     > 
    VBScript Test </ 
     title 
     > 
     </ 
     head 
     > 
     < 
     body 
     > 
     < 
     script 
     language 
     = 
     "vbscript" 
     type 
     = 
     "text/vbscript" 
     > 
     Function 
     multfunction 
     ( 
     x 
     , 
     y 
     ) 
     multfunction 
     = 
     x 
     * 
     y 
     End 
     Function 
     document 
     . 
     write 
     ( 
     multfunction 
     ( 
     4 
     , 
     5 
     )) 
     'This will use your function and insert 4 and 5 into the x and y variables. 
     ' 
     The 
     result 
     will 
     be 
     printed 
     on 
     the 
     screen 
     . 
     </ 
     script 
     > 
     </ 
     body 
     > 
     </ 
     html 
     > 
    
  4. Advertisement

Community Q&A

Search
Add New Question
  • Question
    What's the best software for hacking?
    Wizzwizz4
    Community Answer
    The best software for hacking (for beginners) is probably not VBScript. It is a complicated language that, whilst having some uses, is not really useful for tinkering with existing systems or building new programs. See How to Become a Hacker for more information.
  • Question
    Do I need VBScript on Windows 10?
    Enterlit
    Community Answer
    You need VBScript on all types of Windows computers. VBScript comes with the Windows operating system.
  • Question
    How do I activate different parts of code on a certain day?
    Wizzwizz4
    Community Answer
    First, detect which day it is. Next, compare that to the day that you want. Finally, put the code that you want to run on that day into the body of an if statement.
See more answers
Ask a Question
      Advertisement

      Tips

      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Name
      Please provide your name and last initial
      Thanks for submitting a tip for review!

      About This Article

      Article Summary X

      1. Choose a good code editor.
      2. Create a base HTML page.
      3. Add the VB Script tags.
      4. Declare your variables.
      5. Assign values to the variables.
      6. Use expressions to manipulate the variables.
      7. Create an array.
      8. Make and call a sub procedure.
      9. Create a function procedure.

      Did this summary help you?
      Thanks to all authors for creating a page that has been read 403,017 times.

      Is this article up to date?

      Advertisement