Table of Contents
This updated guide examines How to Program with Vbscript and organizes the essential facts, background, and practical takeaways in clear American English.
Part 1
Setting Up Your Development Environment
Get a good code editor. You can use Notepad, but a more robust editor will make it easier to see the syntax of your VBScript code.
Install Internet Explorer. Internet Explorer is the only browser that supports VBScript, as it is a proprietary Microsoft product. You will need Internet Explorer installed 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.
Learn some basic VBScript practices. 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.
Part 2
Creating a Base Page
Create an HTML page. VBScript exists within HTML websites. 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:
- Open your code editor and enter the following:[1]XResearch source
VBScript Testtitle>head> body>html>
Add the VBScript tags. 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:
VBScript Testtitle>head> script>body>html>
Use VBScript on an ASP server. If you are writing VBScript for an ASP server, you can indicate that the script is starting by using a special tag:
VBScript Testtitle>head> <% %>body>html>
Part 3
Creating a "Hello World!" Program
Insert the Write command. This command is what displays content to the user. When using the write command, the designated text will be displayed in the browser.
VBScript Testtitle>head> document.write()script>body>html>
Add the text that you want to be displayed. 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.
VBScript Testtitle>head> document.write("Hello World!")script>body>html>
Open the HTML file in your browser. Save your code as an. HTML file. Open the saved file using Internet Explorer. The page should displayHello World!in plain text.
Part 4
Using Variables
Declare your variables. Variables allow you to store data to be called upon and manipulated later. You need to declare variables usingdimbefore assigning values to them. You can declare multiple variables at once. Variables must start with a letter, and can be as many as 255 characters long. Below, we are creating the variable "age":
VBScript Testtitle>head> dimagescript>body>html>
Assign values to variable. 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
VBScript Testtitle>head> dimageage=30document.write(age)script>body>html>
Manipulate your variables. 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.
VBScript Testtitle>head> dimxdimydimsumx=10y=5sum=x+ydocument.write(sum)'thepagewilldisplay"15"script>body>html>
Create an array. 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.
VBScript Testtitle>head> Dimnames(2)Dimmothernames(0)="John"names(1)="Jane"names(2)="Pat"mother=names(1)script>body>html>
Create a two-dimensional array. 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.
VBScript Testtitle>head> Dimtable(2,2)'Thiswillcreatea3x3tabletable(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>
Part 5
Using Procedures
Understand the difference between "sub" and "function" procedures. 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.
Make and call a sub procedure. You can use sub procedures to create tasks that your program can all on later. Use theSubandEnd Substatements to enclose the sub procedure. Use theCallstatement to activate the sub procedure
VBScript Testtitle>head> Submysubproc()document.write("This was written in a sub procedure")EndSubCallmysubproc()'Thiswilldisplaythemessagewritteninthesubprocedurescript>body>html>
Create a function procedure. 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 theFunctionandEnd Functionstatements to designate the contents of the function.
VBScript Testtitle>head> Functionmultfunction(x,y)multfunction=x*yEndFunctiondocument.write(multfunction(4,5))'This will use your function and insert 4 and 5 into the x and y variables.'Theresultwillbeprintedonthescreen.script>body>html>
FAQ
What is How to Program with Vbscript about?
It provides a structured overview of vbscript, explains the main context, and highlights practical takeaways for readers.
Why does this topic matter?
Understanding the main concepts helps readers evaluate the issue, avoid common mistakes, and make better-informed decisions.
How should readers use this information?
Use the guidance as a practical starting point, confirm details that may have changed, and follow current product, safety, or security recommendations.
Reader Comments 0
Sign in with email or Google to join the discussion.