AI Generate Classic ASP docs instantly

Classic ASP Cheat Sheet

Quick reference guide with copy-paste ready code snippets

Try DocuWriter Free

Getting Started

3 snippets

Basic Classic ASP syntax

Hello World

<%@ Language=VBScript %>
<html>
<body>
<%
    Response.Write "Hello, World!"
%>
</body>
</html>

ASP Delimiters

<%@ Language=VBScript %>
<% ' Server-side code %>
<%= variable %> <%' Output shorthand %>

Comments

<% ' Single line comment %>

<%
' Multi-line comment
' can span multiple lines
%>

Variables & Data Types

3 snippets

VBScript variable declarations

Variable Declaration

<%
Dim name
Dim age, salary

name = "John Doe"
age = 30
salary = 75000.00
%>

Constants

<%
Const TAX_RATE = 0.0825
Const MAX_ITEMS = 100
Const COMPANY_NAME = "ACME Corp"
%>

Arrays

<%
Dim colors(2)
colors(0) = "Red"
colors(1) = "Green"
colors(2) = "Blue"

' Dynamic array
Dim items()
ReDim items(5)
%>

Control Structures

4 snippets

Conditionals and loops

If-Else

<%
If age >= 18 Then
    Response.Write "Adult"
ElseIf age >= 13 Then
    Response.Write "Teenager"
Else
    Response.Write "Child"
End If
%>

Select Case

<%
Select Case grade
    Case "A"
        Response.Write "Excellent"
    Case "B"
        Response.Write "Good"
    Case "C"
        Response.Write "Average"
    Case Else
        Response.Write "Failed"
End Select
%>

For Loop

<%
For i = 1 To 10
    Response.Write i & "<br>"
Next
%>

For Each Loop

<%
Dim colors
colors = Array("Red", "Green", "Blue")

For Each color In colors
    Response.Write color & "<br>"
Next
%>

Tired of looking up syntax?

DocuWriter.ai generates documentation and explains code using AI.

Try Free

Request & Response

4 snippets

Handling HTTP requests and responses

Query String

<%
Dim userId
userId = Request.QueryString("id")
Response.Write "User ID: " & userId
%>

<!-- URL: page.asp?id=123 -->

Form Data

<%
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
    Dim username, password
    username = Request.Form("username")
    password = Request.Form("password")
    Response.Write "Welcome " & username
End If
%>

Response Methods

<%
' Write output
Response.Write "Hello"  

' Redirect
Response.Redirect "login.asp"

' End processing
Response.End
%>

Cookies

<%
' Set cookie
Response.Cookies("username") = "JohnDoe"
Response.Cookies("username").Expires = DateAdd("d", 30, Now())

' Read cookie
Dim user
user = Request.Cookies("username")
%>

Session & Application

3 snippets

State management objects

Session Variables

<%
' Set session variable
Session("username") = "JohnDoe"
Session("userId") = 1001

' Get session variable
Dim user
user = Session("username")

' Check if exists
If IsEmpty(Session("userId")) Then
    Response.Redirect "login.asp"
End If
%>

Application Variables

<%
' Set application variable (global)
Application.Lock
Application("totalVisits") = Application("totalVisits") + 1
Application.Unlock

' Read application variable
Response.Write "Total Visits: " & Application("totalVisits")
%>

Session Timeout

<%
' Set session timeout to 30 minutes
Session.Timeout = 30

' Abandon session
Session.Abandon
%>

Database Access (ADO)

3 snippets

ActiveX Data Objects

Connect & Query

<%
Dim conn, rs, sql

Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=MyDB;User ID=sa;Password=pass;"

sql = "SELECT * FROM Customers WHERE Country='USA'"
Set rs = conn.Execute(sql)

Do While Not rs.EOF
    Response.Write rs("Name") & "<br>"
    rs.MoveNext
Loop

rs.Close
conn.Close
Set rs = Nothing
Set conn = Nothing
%>

Parameterized Query

<%
Dim conn, cmd, rs

Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "DSN=MyDSN"

Set cmd = Server.CreateObject("ADODB.Command")
cmd.ActiveConnection = conn
cmd.CommandText = "SELECT * FROM Users WHERE UserID = ?"
cmd.Parameters.Append cmd.CreateParameter("@UserID", 3, 1, , 123)

Set rs = cmd.Execute
%>

Insert Record

<%
Dim conn, sql

Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "DSN=MyDSN"

sql = "INSERT INTO Customers (Name, Email) VALUES ('John Doe', 'john@example.com')"
conn.Execute sql

conn.Close
Set conn = Nothing
%>

Server Objects

2 snippets

Server-side object creation

Server.CreateObject

<%
' File System Object
Dim fso, file
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set file = fso.OpenTextFile(Server.MapPath("data.txt"), 1)

' Dictionary Object
Dim dict
Set dict = Server.CreateObject("Scripting.Dictionary")
dict.Add "name", "John"
dict.Add "age", 30
%>

Server Properties

<%
' Map virtual path to physical
Dim physicalPath
physicalPath = Server.MapPath("/images/logo.png")

' HTML encode
Dim encoded
encoded = Server.HTMLEncode("<script>alert('xss')</script>")

' URL encode
Dim urlEncoded
urlEncoded = Server.URLEncode("hello world")
%>

Server-Side Includes

2 snippets

Reusing code with includes

Include Files

<!-- #include file="header.asp" -->
<!-- #include virtual="/includes/footer.asp" -->

<%
' File: relative path from current file
' Virtual: relative to site root
%>

Modular Code

<!-- functions.asp -->
<%
Function CalculateTax(amount)
    CalculateTax = amount * 0.0825
End Function
%>

<!-- main.asp -->
<!-- #include file="functions.asp" -->
<%
Dim total
total = CalculateTax(100)
Response.Write total
%>

More Cheat Sheets

FAQ

Frequently asked questions

What is a Classic ASP cheat sheet?

A Classic ASP cheat sheet is a quick reference guide containing the most commonly used syntax, functions, and patterns in Classic ASP. It helps developers quickly look up syntax without searching through documentation.

How do I learn Classic ASP quickly?

Start with the basics: variables, control flow, and functions. Use this cheat sheet as a reference while practicing. For faster learning, try DocuWriter.ai to automatically explain code and generate documentation as you learn.

What are the most important Classic ASP concepts?

Key Classic ASP concepts include variables and data types, control flow (if/else, loops), functions, error handling, and working with data structures like arrays and objects/dictionaries.

How can I document my Classic ASP code?

Use inline comments for complex logic, docstrings for functions and classes, and README files for projects. DocuWriter.ai can automatically generate professional documentation from your Classic ASP code using AI.

Code Conversion Tools

Convert Classic ASP to Other Languages

Easily translate your Classic ASP code to other programming languages with our AI-powered converters

Related resources

Stop memorizing. Start shipping.

Generate Classic ASP Docs with AI

DocuWriter.ai automatically generates comments, docstrings, and README files for your code.

Auto-generate comments
Create README files
Explain complex code
API documentation
Start Free - No Credit Card

Join 33,700+ developers saving hours every week