asp:debug類調(diào)試程序
asp中最頭疼的就是調(diào)試程序的時候不方便,我想可能很多朋友都會用這樣的方法“response.write ”,然后輸出相關(guān)的語句來看看是否正確。前幾天寫了一個千行的頁面,里面大概有七八個sub/function,調(diào)試的時候用了有三十幾個 response.write ,天,調(diào)試完后把這三十個一個個刪除,累!
今天看到一個asp中的debug類(vbs),試用了一下,絕!
使用方法很簡單:
test.asp
<%
output="xxxx"
set debugstr = new debuggingconsole
debugstr.enabled = true
debugstr.print "參數(shù)output的值", output
''……
debugstr.draw
set debugstr = nothing
%>
===================================================
debuggingconsole.asp
<%
class debuggingconsole
private dbg_enabled
private dbg_show
private dbg_requesttime
private dbg_finishtime
private dbg_data
private dbg_db_data
private dbg_allvars
private dbg_show_default
private divsets(2)
''construktor => set the default values
private sub class_initialize()
dbg_requesttime = now()
dbg_allvars = false
set dbg_data = server.createobject("scripting.dictionary")
divsets(0) = "
今天看到一個asp中的debug類(vbs),試用了一下,絕!
使用方法很簡單:
test.asp
<%
output="xxxx"
set debugstr = new debuggingconsole
debugstr.enabled = true
debugstr.print "參數(shù)output的值", output
''……
debugstr.draw
set debugstr = nothing
%>
===================================================
debuggingconsole.asp
<%
class debuggingconsole
private dbg_enabled
private dbg_show
private dbg_requesttime
private dbg_finishtime
private dbg_data
private dbg_db_data
private dbg_allvars
private dbg_show_default
private divsets(2)
''construktor => set the default values
private sub class_initialize()
dbg_requesttime = now()
dbg_allvars = false
set dbg_data = server.createobject("scripting.dictionary")
divsets(0) = "
|#title#|
|#data#| ||"
divsets(1) = "|#title#|
divsets(1) = "|#title#|
|#data#| ||"
divsets(2) = "
divsets(2) = "
|#title#|
|#data#| ||"
dbg_show_default = "0,0,0,0,0,0,0,0,0,0,0"
end sub
public property let enabled(bnewvalue) ''''[bool] sets "enabled" to true or false
dbg_enabled = bnewvalue
end property
public property get enabled ''''[bool] gets the "enabled" value
enabled = dbg_enabled
end property
public property let show(bnewvalue) ''''[string] sets the debugging panel. where each digit in the string represents a debug information pane in order (11 of them). 1=open, 0=closed
dbg_show = bnewvalue
end property
public property get show ''''[string] gets the debugging panel.
show = dbg_show
end property
public property let allvars(bnewvalue) ''''[bool] sets wheather all variables will be displayed or not. true/false
dbg_allvars = bnewvalue
end property
public property get allvars ''''[bool] gets if all variables will be displayed.
allvars = dbg_allvars
end property
''******************************************************************************************************************
''''@sdescription: adds a variable to the debug-informations.
''''@param: - label [string]: description of the variable
''''@param: - output [variable]: the variable itself
''******************************************************************************************************************
public sub print(label, output)
if dbg_enabled then
if err.number > 0 then
call dbg_data.add(validlabel(label), "/b56/ error: " & err.number & " " & err.description)
err.clear
else
uniqueid = validlabel(label)
response.write uniqueid
call dbg_data.add(uniqueid, output)
end if
end if
end sub
''******************************************************************************************************************
''* validlabel
''******************************************************************************************************************
private function validlabel(byval label)
dim i, lbl
i = 0
lbl = label
do
if not dbg_data.exists(lbl) then exit do
i = i + 1
lbl = label & "(" & i & ")"
loop until i = i
validlabel = lbl
end function
''******************************************************************************************************************
''* printcookiesinfo
''******************************************************************************************************************
private sub printcookiesinfo(byval divsetno)
dim tbl, cookie, key, tmp
for each cookie in request.cookies
if not request.cookies(cookie).haskeys then
tbl = addrow(tbl, cookie, request.cookies(cookie))
else
for each key in request.cookies(cookie)
tbl = addrow(tbl, cookie & "(" & key & ")", request.cookies(cookie)(key))
next
end if
next
tbl = maketable(tbl)
if request.cookies.count <= 0 then divsetno = 2
tmp = replace(replace(replace(divsets(divsetno),"#sectname#","cookies"),"#title#","cookies"),"#data#",tbl)
response.write replace(tmp,"|", vbcrlf)
end sub
''******************************************************************************************************************
''* printsummaryinfo
''******************************************************************************************************************
private sub printsummaryinfo(byval divsetno)
dim tmp, tbl
tbl = addrow(tbl, "time of request",dbg_requesttime)
tbl = addrow(tbl, "elapsed time",datediff("s", dbg_requesttime, dbg_finishtime) & " seconds")
tbl = addrow(tbl, "request type",request.servervariables("request_method"))
tbl = addrow(tbl, "status code",response.status)
tbl = addrow(tbl, "script engine",scriptengine & " " & scriptenginemajorversion & "." & scriptengineminorversion & "." & scriptenginebuildversion)
tbl = maketable(tbl)
tmp = replace(replace(replace(divsets(divsetno),"#sectname#","summary"),"#title#","summary info"),"#data#",tbl)
response.write replace(tmp,"|", vbcrlf)
end sub
''******************************************************************************************************************
''''@sdescription: adds the database-connection object to the debug-instance. to display database-information
''''@param: - osqldb [object]: connection-object
''******************************************************************************************************************
public sub grabdatabaseinfo(byval osqldb)
dbg_db_data = addrow(dbg_db_data, "ado ver",osqldb.version)
dbg_db_data = addrow(dbg_db_data, "oledb ver",osqldb.properties("ole db version"))
dbg_db_data = addrow(dbg_db_data, "dbms",osqldb.properties("dbms name") & " ver: " & osqldb.properties("dbms version"))
dbg_db_data = addrow(dbg_db_data, "provider",osqldb.properties("provider name") & " ver: " & osqldb.properties("provider version"))
end sub
''******************************************************************************************************************
''* printdatabaseinfo
''******************************************************************************************************************
private sub printdatabaseinfo(byval divsetno)
dim tbl
tbl = maketable(dbg_db_data)
tbl = replace(replace(replace(divsets(divsetno),"#sectname#","database"),"#title#","database info"),"#data#",tbl)
response.write replace(tbl,"|", vbcrlf)
end sub
''******************************************************************************************************************
''* printcollection
''******************************************************************************************************************
private sub printcollection(byval name, byval collection, byval divsetno, byval extrainfo)
dim vitem, tbl, temp
for each vitem in collection
if isobject(collection(vitem)) and name <> "server variables" and name <> "querystring" and name <> "form" then
tbl = addrow(tbl, vitem, "{object}")
elseif isnull(collection(vitem)) then
tbl = addrow(tbl, vitem, "{null}")
elseif isarray(collection(vitem)) then
tbl = addrow(tbl, vitem, "{array}")
else
if dbg_allvars then
tbl = addrow(tbl, "" & vitem & "", server.htmlencode(collection(vitem)))
elseif (name = "server variables" and vitem <> "all_http" and vitem <> "all_raw") or name <> "server variables" then
if collection(vitem) <> "" then
tbl = addrow(tbl, vitem, server.htmlencode(collection(vitem))) '' & " {" & typename(collection(vitem)) & "}")
else
tbl = addrow(tbl, vitem, "...")
end if
end if
end if
next
if extrainfo <> "" then tbl = tbl & "
" & extrainfo
tbl = maketable(tbl)
if collection.count <= 0 then divsetno =2
tbl = replace(replace(divsets(divsetno),"#title#",name),"#data#",tbl)
tbl = replace(tbl,"#sectname#",replace(name," ",""))
response.write replace(tbl,"|", vbcrlf)
end sub
''******************************************************************************************************************
''* addrow
''******************************************************************************************************************
private function addrow(byval t, byval var, byval val)
t = t & "| ||" & var & "|= " & val & "|"
addrow = t
end function
''******************************************************************************************************************
''* maketable
''******************************************************************************************************************
private function maketable(byval tdata)
tdata = "|" + tdata + "|"
maketable = tdata
end function
''******************************************************************************************************************
''''@sdescription: draws the debug-panel
''******************************************************************************************************************
public sub draw()
if dbg_enabled then
dbg_finishtime = now()
dim divset, x
divset = split(dbg_show_default,",")
dbg_show = split(dbg_show,",")
for x = 0 to ubound(dbg_show)
divset(x) = dbg_show(x)
next
response.write "
dbg_show_default = "0,0,0,0,0,0,0,0,0,0,0"
end sub
public property let enabled(bnewvalue) ''''[bool] sets "enabled" to true or false
dbg_enabled = bnewvalue
end property
public property get enabled ''''[bool] gets the "enabled" value
enabled = dbg_enabled
end property
public property let show(bnewvalue) ''''[string] sets the debugging panel. where each digit in the string represents a debug information pane in order (11 of them). 1=open, 0=closed
dbg_show = bnewvalue
end property
public property get show ''''[string] gets the debugging panel.
show = dbg_show
end property
public property let allvars(bnewvalue) ''''[bool] sets wheather all variables will be displayed or not. true/false
dbg_allvars = bnewvalue
end property
public property get allvars ''''[bool] gets if all variables will be displayed.
allvars = dbg_allvars
end property
''******************************************************************************************************************
''''@sdescription: adds a variable to the debug-informations.
''''@param: - label [string]: description of the variable
''''@param: - output [variable]: the variable itself
''******************************************************************************************************************
public sub print(label, output)
if dbg_enabled then
if err.number > 0 then
call dbg_data.add(validlabel(label), "/b56/ error: " & err.number & " " & err.description)
err.clear
else
uniqueid = validlabel(label)
response.write uniqueid
call dbg_data.add(uniqueid, output)
end if
end if
end sub
''******************************************************************************************************************
''* validlabel
''******************************************************************************************************************
private function validlabel(byval label)
dim i, lbl
i = 0
lbl = label
do
if not dbg_data.exists(lbl) then exit do
i = i + 1
lbl = label & "(" & i & ")"
loop until i = i
validlabel = lbl
end function
''******************************************************************************************************************
''* printcookiesinfo
''******************************************************************************************************************
private sub printcookiesinfo(byval divsetno)
dim tbl, cookie, key, tmp
for each cookie in request.cookies
if not request.cookies(cookie).haskeys then
tbl = addrow(tbl, cookie, request.cookies(cookie))
else
for each key in request.cookies(cookie)
tbl = addrow(tbl, cookie & "(" & key & ")", request.cookies(cookie)(key))
next
end if
next
tbl = maketable(tbl)
if request.cookies.count <= 0 then divsetno = 2
tmp = replace(replace(replace(divsets(divsetno),"#sectname#","cookies"),"#title#","cookies"),"#data#",tbl)
response.write replace(tmp,"|", vbcrlf)
end sub
''******************************************************************************************************************
''* printsummaryinfo
''******************************************************************************************************************
private sub printsummaryinfo(byval divsetno)
dim tmp, tbl
tbl = addrow(tbl, "time of request",dbg_requesttime)
tbl = addrow(tbl, "elapsed time",datediff("s", dbg_requesttime, dbg_finishtime) & " seconds")
tbl = addrow(tbl, "request type",request.servervariables("request_method"))
tbl = addrow(tbl, "status code",response.status)
tbl = addrow(tbl, "script engine",scriptengine & " " & scriptenginemajorversion & "." & scriptengineminorversion & "." & scriptenginebuildversion)
tbl = maketable(tbl)
tmp = replace(replace(replace(divsets(divsetno),"#sectname#","summary"),"#title#","summary info"),"#data#",tbl)
response.write replace(tmp,"|", vbcrlf)
end sub
''******************************************************************************************************************
''''@sdescription: adds the database-connection object to the debug-instance. to display database-information
''''@param: - osqldb [object]: connection-object
''******************************************************************************************************************
public sub grabdatabaseinfo(byval osqldb)
dbg_db_data = addrow(dbg_db_data, "ado ver",osqldb.version)
dbg_db_data = addrow(dbg_db_data, "oledb ver",osqldb.properties("ole db version"))
dbg_db_data = addrow(dbg_db_data, "dbms",osqldb.properties("dbms name") & " ver: " & osqldb.properties("dbms version"))
dbg_db_data = addrow(dbg_db_data, "provider",osqldb.properties("provider name") & " ver: " & osqldb.properties("provider version"))
end sub
''******************************************************************************************************************
''* printdatabaseinfo
''******************************************************************************************************************
private sub printdatabaseinfo(byval divsetno)
dim tbl
tbl = maketable(dbg_db_data)
tbl = replace(replace(replace(divsets(divsetno),"#sectname#","database"),"#title#","database info"),"#data#",tbl)
response.write replace(tbl,"|", vbcrlf)
end sub
''******************************************************************************************************************
''* printcollection
''******************************************************************************************************************
private sub printcollection(byval name, byval collection, byval divsetno, byval extrainfo)
dim vitem, tbl, temp
for each vitem in collection
if isobject(collection(vitem)) and name <> "server variables" and name <> "querystring" and name <> "form" then
tbl = addrow(tbl, vitem, "{object}")
elseif isnull(collection(vitem)) then
tbl = addrow(tbl, vitem, "{null}")
elseif isarray(collection(vitem)) then
tbl = addrow(tbl, vitem, "{array}")
else
if dbg_allvars then
tbl = addrow(tbl, "" & vitem & "", server.htmlencode(collection(vitem)))
elseif (name = "server variables" and vitem <> "all_http" and vitem <> "all_raw") or name <> "server variables" then
if collection(vitem) <> "" then
tbl = addrow(tbl, vitem, server.htmlencode(collection(vitem))) '' & " {" & typename(collection(vitem)) & "}")
else
tbl = addrow(tbl, vitem, "...")
end if
end if
end if
next
if extrainfo <> "" then tbl = tbl & "
tbl = maketable(tbl)
if collection.count <= 0 then divsetno =2
tbl = replace(replace(divsets(divsetno),"#title#",name),"#data#",tbl)
tbl = replace(tbl,"#sectname#",replace(name," ",""))
response.write replace(tbl,"|", vbcrlf)
end sub
''******************************************************************************************************************
''* addrow
''******************************************************************************************************************
private function addrow(byval t, byval var, byval val)
t = t & "|
addrow = t
end function
''******************************************************************************************************************
''* maketable
''******************************************************************************************************************
private function maketable(byval tdata)
tdata = "|" + tdata + "|"
maketable = tdata
end function
''******************************************************************************************************************
''''@sdescription: draws the debug-panel
''******************************************************************************************************************
public sub draw()
if dbg_enabled then
dbg_finishtime = now()
dim divset, x
divset = split(dbg_show_default,",")
dbg_show = split(dbg_show,",")
for x = 0 to ubound(dbg_show)
divset(x) = dbg_show(x)
next
response.write "
debugging-console:"
call printsummaryinfo(divset(0))
call printcollection("variables", dbg_data,divset(1),"")
call printcollection("querystring", request.querystring(), divset(2),"")
call printcollection("form", request.form(),divset(3),"")
call printcookiesinfo(divset(4))
call printcollection("session", session.contents(),divset(5),addrow(addrow(addrow("","locale id",session.lcid & " (&h" & hex(session.lcid) & ")"),"code page",session.codepage),"session id",session.sessionid))
call printcollection("application", application.contents(),divset(6),"")
call printcollection("server variables", request.servervariables(),divset(7),addrow("","timeout",server.scripttimeout))
call printdatabaseinfo(divset(8))
call printcollection("session static objects", session.staticobjects(),divset(9),"")
call printcollection("application static objects", application.staticobjects(),divset(10),"")
response.write ""
end if
end sub
''destructor
private sub class_terminate()
set dbg_data = nothing
end sub
end class
%>
類的說明:
class debuggingconsole
version: 1.2
public properties
property let enabled(bnewvalue) [bool] sets "enabled" to true or false
property get enabled [bool] gets the "enabled" value
property let show(bnewvalue) [string] sets the debugging panel. where each digit in the string represents a debug information pane in order (11 of them). 1=open, 0=closed
property get show [string] gets the debugging panel.
property let allvars(bnewvalue) [bool] sets wheather all variables will be displayed or not. true/false
property get allvars [bool] gets if all variables will be displayed.
public methods
public sub print (label, output)
adds a variable to the debug-informations.
public sub grabdatabaseinfo (byval osqldb)
adds the database-connection object to the debug-instance. to display database-information
public sub draw ()
draws the debug-panel
methods detail
public sub print (label, output)
parameters: - label [string]: description of the variable
- output [variable]: the variable itself
public sub grabdatabaseinfo (byval osqldb)
parameters: - osqldb [object]: connection-object
call printsummaryinfo(divset(0))
call printcollection("variables", dbg_data,divset(1),"")
call printcollection("querystring", request.querystring(), divset(2),"")
call printcollection("form", request.form(),divset(3),"")
call printcookiesinfo(divset(4))
call printcollection("session", session.contents(),divset(5),addrow(addrow(addrow("","locale id",session.lcid & " (&h" & hex(session.lcid) & ")"),"code page",session.codepage),"session id",session.sessionid))
call printcollection("application", application.contents(),divset(6),"")
call printcollection("server variables", request.servervariables(),divset(7),addrow("","timeout",server.scripttimeout))
call printdatabaseinfo(divset(8))
call printcollection("session static objects", session.staticobjects(),divset(9),"")
call printcollection("application static objects", application.staticobjects(),divset(10),"")
response.write ""
end if
end sub
''destructor
private sub class_terminate()
set dbg_data = nothing
end sub
end class
%>
類的說明:
class debuggingconsole
version: 1.2
public properties
property let enabled(bnewvalue) [bool] sets "enabled" to true or false
property get enabled [bool] gets the "enabled" value
property let show(bnewvalue) [string] sets the debugging panel. where each digit in the string represents a debug information pane in order (11 of them). 1=open, 0=closed
property get show [string] gets the debugging panel.
property let allvars(bnewvalue) [bool] sets wheather all variables will be displayed or not. true/false
property get allvars [bool] gets if all variables will be displayed.
public methods
public sub print (label, output)
adds a variable to the debug-informations.
public sub grabdatabaseinfo (byval osqldb)
adds the database-connection object to the debug-instance. to display database-information
public sub draw ()
draws the debug-panel
methods detail
public sub print (label, output)
parameters: - label [string]: description of the variable
- output [variable]: the variable itself
public sub grabdatabaseinfo (byval osqldb)
parameters: - osqldb [object]: connection-object
相關(guān)文章
- ASP怎么談到應(yīng)用到類的?
- 檢測函數(shù) asp class
- 遭遇ASP類的事件設(shè)計
- ASP高亮類
- Object對象的一些的隱藏函數(shù)介紹
- 淺談ASP中的類
- 在VBScript中使用類
- ASP 類專題
- 代碼與頁面的分離
- ASP代碼的對象化
- 一個asp快速字符串連接類
- 一個簡單的asp數(shù)據(jù)庫操作類
- ASP類編寫詳細說明
- 實現(xiàn)支持邏輯搜索/單詞搜索/詞組搜索+支持OR/AND關(guān)鍵字的VBS CLASS!
- ASP類Class入門 推薦
- 創(chuàng)建一個ASP通用分頁類
- 如何編寫一個ASP類
- 一個ACCESS數(shù)據(jù)庫訪問的類第1/3頁
- 分頁類,異常類
- ASP 類 Class入門