VBScript is a Windows native programming language that is generally used to create web server applications. VBScript is included in an HTML file, and is fairly easy to use. Keep in mind that VBScript is not the same as Visual Basic which is usually used for programming desktop applications.
Step
Part 1 of 5: Preparing the Program Development Environment
Step 1. Get a good code editor
You can use Notepad, but a better editor will make it easier for you to see the syntax of your VBScript code.
Step 2. Install Internet Explorer
Internet Explorer is the only browser that supports VBScript because VBScript is a patented Microsoft product. You need Internet Explorer installed on your computer in order to see the results of running VBScript programs.
Since Internet Explorer is only supported on Windows, you can get the best results by creating the program using a Windows computer
Step 3. Learn some basic VBScript exercises
There are some basics that will be helpful if you know them before getting into writing too deep code.
- Use ' (one quotation mark) to mark comments. Any lines starting with single quotes are marked as comments and are not processed by the script. Use comments frequently to help other app developers and yourself understand what your code is doing.
- Use _ (underscore) to continue at the end of the line. The end of one line of code is usually indicated by a move to the next line, but if the line of code you have written is too long and must be continued on the next line, put a _ at the end of the unfinished line to indicate that the line of code will be continued on the next line.
Part 2 of 5: Creating a Basic Page
Step 1. Create an HTML page
VBScript is contained in HTML websites. To see how VBScript performs, you need to create an HTML file that can be opened with Internet Explorer. Open your code editor, then enter the following code:
VBScript Test
Step 2. Add VBScript flags
When creating web pages using VBScript, you must tell the browser which script to run. Insert the following flag into your HTML page:
VBScript Test
Step 3. Use VBScript on the ASP server
If you are writing VBScript for an ASP server, you can mark the beginning of the script using a special flag:
VBScript Test <% %>
Part 3 of 5: Creating the "Hello World!" Program
Step 1. Enter the Write command
This command serves to display the content to the user. When using the Write command, the specified text will be displayed in the browser.
VBScript Test
Step 2. Add the text you want to display
Inside the brackets, enter the text you want to appear on the screen. Don't forget to enclose the text with quotes to designate the text as data of type string.
VBScript Test
Step 3. Open the HTML file with your browser
Save your code as an. HTML file. Open the file you saved using Internet Explorer. Your page should show Hello World! in plain text.
Part 4 of 5: Using Variables
Step 1. Start by declaring your variables
You can store data in variables, then you can call and manipulate them later. You need to declare variables using dim before filling them with values. You can declare multiple variables at once. Variables must start with a letter, and can be up to 255 characters long. Below, we create the "age" variable:
VBScript Test
Step 2. Enter the value into the variable
After declaring a variable, you can enter values into it. Use the = sign to specify the value of the variable. You can use the Write command to display the variables on the screen to make sure that everything is working properly.
VBScript Test
Step 3. Try to manipulate the variables
You can use mathematical statements to manipulate variables. The mathematical statements used work like basic algebra. All variables, including your answer, must be declared before being used.
VBScript Test
Step 4. Create an array
In essence, an Array is a table that contains more than one value. After that, the array is handled as a single variable. Like all variables, arrays must be declared first. You must indicate the number of values the array can store (including 0 as the first number). After that, you can call the data stored in the array later.
VBScript Test
Step 5. Create a two-dimensional array
You can create arrays of multiple dimensions to store more data. When declaring an array, you must indicate the number of rows and columns the array holds.
VBScript Test
Part 5 of 5: Using Procedures
Step 1. 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 values to the program.
- Function procedures can perform actions and return values to the program.
Step 2. Create and call the sub procedure
You can use sub procedures to create tasks that your program can call later. Use the Sub and End Sub statements to enclose the contents of the sub procedure. Use the Call statement to activate the sub procedure.
VBScript Test
Step 3. Create a function procedure
Function procedures allow you to execute commands and return values to the program. The function procedure is where the main functionality of your program will run. Use the Function and End Function statements to enclose the contents that are executed inside the function procedure.
VBScript Test