譯者的話:
不知道用asp寫代碼的朋友是不是和我有一樣的感受,asp中最頭疼的就是調試程序的時候不方便,我想可能很多朋友都會用這樣的方法“response.write ”,然後輸出相關的語句來看看是否正確。前幾天寫了一個千行的頁面,裡面大概有七八個sub/function,調試的時候用了有三十幾個response.write ,天,調試完後把這三十個一個個刪除,累!
今天看到一個asp中的debug類(vbs),試用了一下,絕!
使用方法很簡單:
test.asp
<!--#include file=debuggingconsole.asp-->
<%
output=xxxx
set debugstr = new debuggingconsole
debugstr.enabled = true
debugstr.print 參數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) = <tr><td style='cursor:hand;' onclick=javascript:if (document.getelementbyid('data#sectname#').style.display=='none'){document.getelementbyid( 'data#sectname#').style.display='block';}else{document.getelementbyid('data#sectname#').style.display='none';}><div id=sect#sectname# style =font-weight:bold;cursor:hand;background:#7ea5d7;color:white;padding-left:4;padding-right:4;padding-bottom:2;>|#title#| <div id=data# sectname# style=cursor:text;display:none;background:#ffffff;padding-left:8; onclick=window.event.cancelbubble = true;>|#data#| </div>|</div>|
divsets(1) = <tr><td><div id=sect#sectname# style=font-weight:bold;cursor:hand;background:#7ea5d7;color:white;padding-left:4;padding-right: 4;padding-bottom:2; onclick=javascript:if (document.getelementbyid('data#sectname#').style.display=='none'){document.getelementbyid('data#sectname#').style. display='block';}else{document.getelementbyid('data#sectname#').style.display='none';}>|#title#| <div id=data#sectname# style=cursor:text; display:block;background:#ffffff;padding-left:8; onclick=window.event.cancelbubble = true;>|#data#| </div>|</div>|
divsets(2) = <tr><td><div id=sect#sectname# style=background:#7ea5d7;color:lightsteelblue;padding-left:4;padding-right:4;padding-bottom:2;>| #title#| <div id=data#sectname# style=display:none;background:lightsteelblue;padding-left:8>|#data#| </div>|</div>|
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), !!! error: & err.number & & err.description)
err.clear
else
uniqueid = validlabel(label)
response.write uniqueid
call dbg_data.add(unique