ASP 快速参考

内置对象、常用函数、错误码、指令的一页速查。

Intermediate
Key Points把最常用的对象成员、VBScript 函数、常见错误号集中在一页,写代码时随手查。

内置对象

ObjectKey members
RequestQueryString、Form、Cookies、ServerVariables、TotalBytes、BinaryRead
ResponseWrite、BinaryWrite、Redirect、End、Flush、Buffer、ContentType、Charset、Status、AddHeader、Cookies、CacheControl、Expires
SessionSessionID、Timeout、CodePage、LCID、Contents、Abandon
ApplicationContents、StaticObjects、Lock、Unlock
ServerCreateObject、MapPath、HTMLEncode、URLEncode、Execute、Transfer、ScriptTimeout、GetLastError

常用函数

CategoryFunctions
StringLen、Left、Right、Mid、InStr、InStrRev、Replace、Split、Join、Trim、LTrim、RTrim、UCase、LCase、String、Space、StrReverse
MathAbs、Int、Fix、Round、Rnd、Randomize、Sqr、Exp、Log
DateNow、Date、Time、Year、Month、Day、Hour、Minute、Second、Weekday、DateAdd、DateDiff、DatePart、DateSerial、FormatDateTime
TypeCStr、CInt、CLng、CDbl、CDate、CBool、IsNull、IsEmpty、IsNumeric、IsDate、IsArray、IsObject、TypeName、VarType
ArrayArray、Split、Join、UBound、LBound、Filter
FormatFormatNumber、FormatCurrency、FormatPercent、FormatDateTime

常用语句

ASP
<%
    ' 条件
    If x > 0 Then
        ' ...
    ElseIf x = 0 Then
        ' ...
    Else
        ' ...
    End If

    ' 多分支
    Select Case n
        Case 1 : Response.Write "一"
        Case 2, 3 : Response.Write "二或三"
        Case Else : Response.Write "其它"
    End Select

    ' 循环
    For i = 1 To 10 Step 2
    Next

    For Each item In collection
    Next

    Do While Not rs.EOF
        rs.MoveNext
    Loop

    Do Until x > 10
        x = x + 1
    Loop
%>

指令

ASP
<%@ Language="VBScript" CodePage="65001" %>
<% Option Explicit %>
<% Response.Buffer = True %>
<% Session.CodePage = 65001 %>
<% Response.Charset = "UTF-8" %>
<!-- #include virtual="/includes/funcs.asp" -->

常见错误号

NumberMeaningTypical fix
800a000d对字符串做算术先 CInt / CDbl
800a01f4Option Explicit 下用了未声明变量Dim 声明
800a01b6调用了不存在的方法查组件文档
800a0046写文件没有权限给 IUSR 加写权限
800a0035路径错或文件不存在MapPath 检查
80004005数据库连接失败查连接串与驱动
800a0009数组或集合越界先判 UBound / Count

HTTP 状态码

ASP
<%
    Response.Status = "404 Not Found"
    Response.Status = "403 Forbidden"
    Response.Status = "500 Internal Server Error"
    Response.Status = "301 Moved Permanently"
    Response.AddHeader "Location", "https://example.com/new"
%>

Friends & Partners