Asp Quick Ref in ASP
Sure! Here's a quick reference cheat sheet for Classic ASP (VBScript) essentials to help you get started or refresh quickly:
Classic ASP Quick Reference
1. Basic Syntax
<% ' VBScript code block Response.Write "Hello World"%>2. Variables
Dim namename = "Alice"Response.Write name3. Comments
' This is a comment4. Data Types
String, Integer, Double, Boolean, Date, Object, Variant (default)
No explicit declaration needed.
5. Operators
| Operator | Meaning |
|---|---|
| + | Addition/Concat |
| - | Subtraction |
| * | Multiplication |
| / | Division |
| = | Assignment |
| & | String concat |
| And, Or | Logical ops |
6. Control Structures
If...Then...Else
If x > 10 Then Response.Write "Greater than 10"Else Response.Write "10 or less"End IfSelect Case
Select Case color Case "Red" Response.Write "Stop" Case "Green" Response.Write "Go" Case Else Response.Write "Wait"End Select7. Loops
For...Next
For i = 1 To 5 Response.Write i & "<br>"NextFor Each...Next
For Each item In collection Response.Write item & "<br>"NextDo While
Do While condition ' codeLoop8. Functions & Subs
Sub SayHello(name) Response.Write "Hello " & nameEnd SubFunction Add(a, b) Add = a + bEnd FunctionSayHello("Bob")Response.Write Add(5, 3)9. Common Objects
| Object | Purpose |
|---|---|
| Request | Get form/query/cookie data |
| Response | Send output to client |
| Server | Utilities like CreateObject |
| Session | Store per-user data |
| Application | Store global app data |
10. Form Handling
<form method="post" action="process.asp"> Name: <input name="username" /> <input type="submit" /></form><!-- process.asp --><%Dim namename = Request.Form("username")Response.Write "Hello " & Server.HTMLEncode(name)%>11. Include Files
<!--#include file="header.asp" -->12. Database Example (using ADO)
<%Dim conn, rs, sqlSet conn = Server.CreateObject("ADODB.Connection")conn.Open "your_connection_string"sql = "SELECT * FROM users"Set rs = conn.Execute(sql)Do While Not rs.EOF Response.Write rs("username") & "<br>" rs.MoveNextLooprs.CloseSet rs = Nothingconn.CloseSet conn = Nothing%>13. Session Example
Session("UserName") = "Alice"Response.Write "Welcome, " & Session("UserName")14. Error Handling
On Error Resume Next' risky code hereIf Err.Number <> 0 Then Response.Write "Error: " & Err.Description Err.ClearEnd IfOn Error GoTo 0If you want a more detailed cheat sheet on any of these topics or others like FileSystemObject, Cookies, or Application Events, just ask!