ACTIVE SERVER PAGESActive Server Pages (ASP), also known as Classic ASPor ASP Classic, was Microsofts first server-side scriptengine for dynamically generated web pages. Initiallyreleased as an add-on to Internet Information Services(IIS) via the Windows NT 4.0 Option Pack, it wassubsequently included as a free component of WindowsServer. ASP.NET has superseded ASP.The Active Scripting engines support of theComponent Object Model (COM) enables ASP websitesto access functionality in compiled libraries such asDLLs.
The use of ASP pages with Internet Information Services(IIS) is currently supported on all supported versions ofIIS. Web pages with the .asp file extension use ASP, althoughsome web sites disguise their choice of scriptinglanguage for security purposes Pages with the .aspxextension use compiled ASP.NET which makes themfaster and more robust than server-side scripting in ASP,which is interpreted at run-time; however, ASP.NETpages may still include some ASP scripting. Theintroduction of ASP.NET led to use of the term ClassicASP for the original technology.
VBSCRIPT Using VBScript in ASP pages is very simple. The interpreterreplaces all the code in between the <% and %> tags. In theexample below Response.Write Now() dynamically replacedby the current time of the server. <html> <head> <title>Kaushik Enterprises</title> </head> <body>The servers current time:<br /> <% Response.Write Now() %> </body> </html>
VBScript is not case sensitive foo is the same thing as FOO This applies to everything variable names, constant names keywords subroutine/function names object names
VARIABLE SCOPEVariables declared outside of asubroutine or function (VBScript hasboth) are global.Variables declared in a subroutine orfunction are created and destroyedeach time the procedure is called.(local variables)
THE ACTIVE SERVER PAGES MODEL• An ASP script begins to run when a browser requestsa .asp file from your Web server.• Web server then calls ASP, which reads through therequested file from top to bottom, executes any ASPstatements, and sends an HTML page to the browser.
ASP SCRIPTING• The first line in an .asp file specifies the scriptinglanguage for the page. For example, the followingfirst line in .asp file specifies that the script isVBScript:<%@ LANGUAGE=VBScript %>• Without a language tag, script in the file is processedas the default language (VBScript by default.) underthe ASP entry in the Web server registry.• Active Server Pages can provide a scriptingenvironment for a number of other scriptinglanguages, including Jscript (build-in), REXX, andPerl, and others.
DEVELOPING ASP SCRIPTSCreating/Revising ASP scriptsPosting ASP scripts on the web server orsaving them on the local web serverTesting ASP Scripts
SETTING UP ASP FILES• An Active Server Pages (ASP) file is a text file with theextension .asp that contains any combination of the following:– Text– HTML tags– ASP script commands– Call to ActiveX server components• ASP is server-side scripting.• ASP files only work with the IIS on NT or PWS on Windows95.• .asp files should be saved on your Web site in a directory thathas Script or Execute permission enabled.
DATA TYPES• Variables: Simple variables and Array variables• VBScript subsumes all categories of data under one name called a Variant.• At a basic level, Variants contain either string or numeric data.• String data is used for text, while numeric data contains only numbers.• Variant data can be further classified into subtypes. For example, you canhave numeric data that represents currency, or a date or time, and theVariant will interpret the data accordingly.• You can use the data type conversion function for data type conversion. Forexample, CInt function to force conversion of an expression to the Variantof subtype Integer.
DECLARING VARIABLES VBScript implicitly creates a variable the first time that itencounters an unrecognized string of characters that could be avariable name. The Option Explicit statement informs VBScript to generate anerror if it encounters an undeclared variable. The Option Explicitstatement should be the first line of code in a script that usesvariables. Dim varname[([subscripts])][, varname[([subscripts])]] . . . Dim a, x(10), y(2, 5) A variable name: Must begin with an alphabetic character. Cannot contain an embedded period. Must not exceed 255 characters. Must be unique. Is not case-sensitive.
USE PROCEDURES TO STRUCTURED CODE Structured code consists of compact chunks of related code that aretermed procedures. Procedures are reusable code that can be called from anywhere inyour script. The main benefits of structured coding are as follows: Maintenance—when related code is grouped, it is easier tomaintain. When code needs to be updated or modified, you canmake the changes in a single code segment rather thanthroughout an entire program. Debugging—because the code is modular, you can pinpointwhere an error occurs and conduct your debugging efforts in thecode segment where the error occurred. Reusability—you can call the procedures from anywhere inyour script, as well as use the code segments in other programsthat require the same procedures.
SCOPE OF A VARIABLE• If a variable is declared outside of a procedure, it isvisible throughout the program.• If a variable is declared inside a procedure, it is onlyvisible inside that procedure.• The range of a variable’s visibility is called its scope.• In VBScript:– Scope is either script-level or procedure-level.– A variable is in effect within its scope.– Variable names must be unique within their scope.– Variables should always be defined with the smallest scope possible.
WHAT IS AN OBJECT?• An object is simply a collection of functions and datagrouped together. Typically, most of the object’sfunctionality (particularly its data structure) is hiddenfrom the programmer, who uses the object’s interface, ormodel, to control the object. The object’s interfaceconsists of a published set of functions and data. In pureobject-oriented systems, data are private and thereforecannot be accessed by external object directly.• Methods: The procedures that an object exposes throughits interface are called methods. Methods are typicallyfunctions and return a value.
Properties: The variables that are part of an object arecalled properties: Reading a property’s value is called getting the property’s value. Writing a value to a property is called setting the property’s value. Properties can be read-only or read/write depending on the design ofthe object.