CSC378 ยท 2076 ยท 5 marks
What is VB Script in ASP?
What is VB Script in ASP?[5]
Quick answer
VBScript (Visual Basic Scripting Edition) is a lightweight scripting language developed by Microsoft, based on Visual Basic. In the context of Active Server Pages (ASP), VBScript is the default scripting language used to write server-side scripts that are executed on the web server to generate dynamic HTML content sent to the client's browser.
VB Script in ASP
Definition
Key Characteristics of VBScript in ASP
1. Server-Side Execution
VBScript code embedded in ASP pages is executed on the server, not on the client browser. The server processes the script and sends only the resulting HTML to the browser.
2. Syntax and Delimiters
VBScript code in ASP is enclosed within special delimiters:
<% VBScript code here %>
Or using the script tag:
<script language="VBScript" runat="server">
' code here
</script>
3. Basic Example
<%
Dim strName
strName = "TU CSIT Student"
Response.Write("Hello, " & strName)
%>
Output sent to browser:
Hello, TU CSIT Student
Features of VBScript in ASP
| Feature | Description |
|---|---|
| Default Language | VBScript is the default scripting language for Classic ASP |
| Case Insensitive | Variable names and keywords are not case-sensitive |
| Loosely Typed | All variables are of type Variant; no need to declare data types |
| Built-in Objects | Works with ASP built-in objects like Request, Response, Session, Application, Server |
| Interpreted | Scripts are interpreted at runtime on the server |
| No Compilation | Does not require pre-compilation like compiled languages |
VBScript with ASP Built-in Objects
VBScript interacts with ASP's built-in objects to handle web functionality:
<%
' Reading form data using Request object
Dim username
username = Request.Form("username")
' Writing output using Response object
Response.Write("Welcome, " & username)
' Using Session object
Session("user") = username
%>
Conditional and Loop Example
<%
Dim i
For i = 1 To 5
Response.Write("Number: " & i & " ")
Next
%>
Output:
Number: 1
Number: 2
Number: 3
Number: 4
Number: 5
Advantages of VBScript in ASP
- Easy to learn for developers familiar with Visual Basic
- Tight integration with Microsoft technologies (IIS, COM objects)
- Dynamic content generation -- pages change based on user input or database data
- Access to databases through ADO (ActiveX Data Objects)
- Reusable code through procedures and functions
Limitations
- Runs only on Microsoft IIS server (not cross-platform)
- Slower compared to compiled languages
- Replaced by ASP.NET which uses VB.NET or C# for more powerful server-side development
Summary
VBScript in ASP provides a simple, powerful way to create dynamic, data-driven web pages by embedding server-side scripting logic directly within HTML. It uses ASP's built-in objects to handle requests, responses, sessions, and server operations, making it the foundation of Classic ASP web development on Microsoft platforms.
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.