How to Program in VBScript: 3 Steps (with Pictures)

Table of contents:

How to Program in VBScript: 3 Steps (with Pictures)
How to Program in VBScript: 3 Steps (with Pictures)
Anonim

VBScript is a native Windows programming language which is mainly used to create web server applications. VBScript is integrated into HTML files, and it's pretty straightforward. Note that VBScript is different from Visual Basic, which is used for desktop programming.

Steps

Part 1 of 5: Setting up the Development Environment

229827 1 1
229827 1 1

Step 1. Get a good code editor

You can use Notepad, but a more robust editor will allow you to view the syntax of the VBScript code more easily.

229827 2 1
229827 2 1

Step 2. Install Internet Explorer

It is the only browser that supports VBScript, as it is a Microsoft proprietary product. You will need to install this program to see VBScript in action.

Internet Explorer is only supported by Windows, so it will be easier to follow these steps on a Windows computer

229827 3 1
229827 3 1

Step 3. Learn basic VBScript practices

There are many important basic concepts that will be useful to you before you throw yourself headlong into programming.

  • Use '(apostrophe) to designate a comment. All lines starting with an apostrophe are comments, and are not considered part of the program. Use the comments often to help other developers - and yourself - understand what the code does.
  • Use _ (underscore) to extend the term by a line. The end of a line of code is typically indicated by simply moving to the next line, but if the line becomes very long and needs to continue on the next line, write a _ at the end of the line to continue.

Part 2 of 5: Creating a Basic Page

Step 1. Create an HTML page

VBScript exists within HTML websites. In order for your code to work, you will need to create an HTML file that you can open in Internet Explorer. Open the code editor and enter the following text:

  VBScript Test    

Step 2. Add VBScript tags

When you create a web page with VBScript, you need to tell the browser that you are going to insert a script. Insert the tag in your HTML source:

  VBScript Test    

Step 2. Add the text you want to display

Between the brackets, enter the text you want to display on the screen. Enclose the text in question marks to indicate it as a string.

  VBScript Test    

Step 3. Open the HTML file in your browser

Save the code as an. HTML file. Open the saved file using Internet Explorer. The page should show Hello World! in plain text.

Part 4 of 5: Using Variables

Step 1. Declare your variables

Variables allow you to store data that you can recall and manipulate later. You will need to declare the variables with the statement dim before you can assign values to them. You can declare multiple variables at once. Variables must start with a letter, which can be up to 255 characters long. Next, we will create the "age" variable:

  VBScript Test    

Step 2. Assign values to variables

Now that you have declared the variable, you can assign it a value. Use the = symbol to do this. You can use the Write command to display the variable on the screen and verify that everything works.

  VBScript Test  

Step 3. Manipulate your variables

You can use mathematical expressions to manipulate the data you have stored in your variables. These expressions work like basic algebra. You will need to declare all variables, including the response, before using them.

  VBScript Test    

Step 4. Create an array

An array is essentially a table that contains more than one value. It is then considered as a single variable. Like variables, the array must first be declared. You will also need to indicate the number of values that can be stored in the array (including 0 as the first number). You can then recall the data stored in the array later.

  VBScript Test    

Step 5. Create a two dimensional array

You can create an array with multiple dimensions to store more data. When you declare the array, you will need to indicate the number of rows and columns contained within.

  VBScript Test    

Part 5 of 5: Using Procedures

Step 1. Learn the difference between the "sub" and "function" procedures

These two types of procedures allow the program to perform actions.

  • Sub procedures can perform actions, but they cannot return a value to the program.
  • Function procedures can call other procedures and return values.

Step 2. Write and call a sub procedure

You can use these procedures to create tasks that your program can call later. Use the Sub and End Sub statements to identify the sub procedure. Use the statement Call to activate the sub procedure.

  VBScript Test    

Step 3. Create a Function procedure

A Function procedure allows you to execute commands and return values to the program. Function procedures are the ones that form the body of your program. Use the statements Function and End Function to identify the contents of the function.

  VBScript Test    

Recommended: