![]() | |||||||||||||||||||||
![]() |
|
|
by Derrald Farnsworth-Livingston Introduction
Active Server Pages or ASP is a technology developed by Microsoft to further the ability to write applications for the web. Active Server Pages can be written in Visual Basic Script or Javascript and contain the ability to be dynamic. What this means is that a few lines of code can create pages that can change minute to minute. For instance, many applications that access and manipulate data in databases are now being written in ASP and as the database is updated the web pages are also updated. In this tutorial we will focus on the Visual Basic Scripting side of ASP and demonstrate how a few functions work within this technology.
In order to properly utilize Active Server Pages technology you must either have a Windows NT 4.0 Server or greater with IIS 3.0 or greater or Windows NT 4.0 Workstation or greater with PWS installed. Once this service is installed and running we must find the root web directory. For ease we will the default web site that is normally installed. Multiple websites can later be added to this. The default directory for these pages is c:\inetpub\wwwroot\. When we place files in this directory they should be able to be accessed via this directory. As an example place a simple text file in this directory and then using the server console try to access this file by typing http://localhost/filename.txt where filename.txt is the file that you placed in this directory. If this succeeds you have placed the file in the proper location and have the server software correctly installed.
We want to now create dynamic web pages. Let's start with the basics. First off all ASP 3.0 pages are designated with the file extension of .asp. This tells the server to access the asp.dll library to process the page.
Secondly all ASP code must fall between these two designators:
The <% %> tells the server to process that information as ASP. The next line after the intial <% needs to be:
This tells the server that the language that will be used to create these pages is VBScript. We can now Visual Basic Scripting code within these brackets. An easy and useful element to begin with is the write method of the response object. Response.write has the ability to display on the page either a string or a value from a variable. For instance:
Whereas the HTML code would be five lines:
This is a very simplistic and unstructured example, but it shows where a working knowledge of ASP can cut down on our coding and make our lives easier. In the previous examples a variable of "i" is used to move through the for-next loop. All variables in ASP should be declared by using a "Dim" statement:
This declares the "i" variable as a variant type. A variant type of variable means that "i" can contain an integer, float, string, etc. All constants must be declared using the "Const" statement:
To make sure all variables are declared an "Option Explicit" should be one of the first lines in the code. By the way, many programmers do not include this statement and create variables on the fly. The previous for-next loop example would work without first declaring "i" but it is considered bad, unstructured programming. In the rest of the examples it will be assumed that "Option Explicit" proceeds the example as does the variable declarations.
|
Section 2: Loop-the-Loop Section 3: Make a Statement Section 4: Final Results
| ||||||||||||||||||||||