asp:debug类调试程序

2018-09-06 11:27

阅读:521

  ASP中最头疼的就是调试程序的时候不方便,我想可能很多朋友都会用这样的方法“response.write”,然后输出相关的语句来看看是否正确。前几天写了一个千行的页面,里面大概有七八个SUB/FUNCTION,调试的时候用了有三十几个response.write,天,调试完后把这三十个一个个删除,累!

今天看到一个ASP中的Debug类(VBS),试用了一下,绝!

使用方法很简单:

test.asp

<!--#INCLUDEFILE=debuggingConsole.asp-->
<%
output=XXXX
Setdebugstr=NewdebuggingConsole
debugstr.Enabled=true
debugstr.Print参数output的值,output
……
debugstr.draw
Setdebugstr=Nothing
%>

===================================================

debuggingConsole.asp

<%
ClassdebuggingConsole

privatedbg_Enabled
privatedbg_Show
privatedbg_RequestTime
privatedbg_FinishTime
privatedbg_Data
privatedbg_DB_Data
privatedbg_AllVars
privatedbg_Show_default
privateDivSets(2)

Construktor=>setthedefaultvalues
PrivateSubClass_Initialize()
dbg_RequestTime=Now()
dbg_AllVars=false
Setdbg_Data=Server.CreateObject(Scripting.Dictionary)
DivSets(0)=<TR><TDstyle=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;}><DIVid=sect#sectname#style=font-weight:bold;cursor:hand;background:#7EA5D7;color:white;padding-left:4;padding-right:4;padding-bottom:2;>#title#<DIVid=data#sectname#style=cursor:text;display:none;background:#FFFFFF;padding-left:8;onclick=window.event.cancelBubble=true;>#data#</DIV></DIV>
DivSets(1)=<TR><TD><DIVid=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#<DIVid=data#sectname#style=cursor:text;display:block;background:#FFFFFF;padding-left:8;onclick=window.event.cancelBubble=true;>#data#</DIV></DIV>
DivSets(2)=<TR><TD><DIVid=sect#sectname#style=background:#7EA5D7;color:lightsteelblue;padding-left:4;padding-right:4;padding-bottom:2;>#title#<DIVid=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
EndSub

PublicPropertyLetEnabled(bNewValue)[bool]Setsenabledtotrueorfalse
dbg_Enabled=bNewValue
EndProperty
PublicPropertyGetEnabled[bool]Getstheenabledvalue
Enabled=dbg_Enabled
EndProperty

PublicPropertyLetShow(bNewValue)[string]Setsthedebuggingpanel.Whereeachdigitinthestringrepresentsadebuginformationpaneinorder(11ofthem).1=open,0=closed
dbg_Show=bNewValue
EndProperty
PublicPropertyGetShow[string]Getsthedebuggingpanel.
Show=dbg_Show
EndProperty

PublicPropertyLetAllVars(bNewValue)[bool]Setswheatherallvariableswillbedisplayedornot.true/false
dbg_AllVars=bNewValue
EndProperty
PublicPropertyGetAllVars[bool]Getsifallvariableswillbedisplayed.
AllVars=dbg_AllVars
EndProperty

******************************************************************************************************************
@SDESCRIPTION:Addsavariabletothedebug-informations.
@PARAM:-label[string]:Descriptionofthevariable
@PARAM:-output[variable]:Thevariableitself
******************************************************************************************************************
PublicSubPrint(label,output)
Ifdbg_EnabledThen
iferr.number>0then
calldbg_Data.Add(ValidLabel(label),!!!Error:&err.number&&err.Description)
err.Clear
else
uniqueID=ValidLabel(label)
response.writeuniqueID
calldbg_Data.Add(uniqueID,output)
endif
EndIf
EndSub

******************************************************************************************************************
*ValidLabel
******************************************************************************************************************
PrivateFunctionValidLabel(byvallabel)
dimi,lbl
i=0
lbl=label
do
ifnotdbg_Data.Exists(lbl)thenexitdo
i=i+1
lbl=label&(&i&)
loopuntili=i

ValidLabel=lbl
EndFunction

******************************************************************************************************************
*PrintCookiesInfo
******************************************************************************************************************
PrivateSubPrintCookiesInfo(byvalDivSetNo)
dimtbl,cookie,key,tmp
IfNotRequest.Cookies(cookie).HasKeysThen
tbl=AddRow(tbl,cookie,Request.Cookies(cookie))
Else
ForEachkeyinRequest.Cookies(cookie)
tbl=AddRow(tbl,cookie&(&key&),Request.Cookies(cookie)(key))
Next
EndIf
Next

tbl=MakeTable(tbl)
ifRequest.Cookies.count<=0thenDivSetNo=2
tmp=replace(replace(replace(DivSets(DivSetNo),#sectname#,COOKIES),#title#,COOKIES),#data#,tbl)
Response.Writereplace(tmp,,vbcrlf)
endsub

******************************************************************************************************************
*PrintSummaryInfo
******************************************************************************************************************
PrivateSubPrintSummaryInfo(byvalDivSetNo)
dimtmp,tbl
tbl=AddRow(tbl,TimeofRequest,dbg_RequestTime)
tbl=AddRow(tbl,ElapsedTime,DateDiff(s,dbg_RequestTime,dbg_FinishTime)&seconds)
tbl=AddRow(tbl,RequestType,Request.ServerVariables(REQUEST_METHOD))
tbl=AddRow(tbl,StatusCode,Response.Status)
tbl=AddRow(tbl,ScriptEngine,ScriptEngine&&ScriptEngineMajorVersion&.&ScriptEngineMinorVersion&.&ScriptEngineBuildVersion)
tbl=MakeTable(tbl)
tmp=replace(replace(replace(DivSets(DivSetNo),#sectname#,SUMMARY),#title#,SUMMARYINFO),#data#,tbl)
Response.Writereplace(tmp,,vbcrlf)
EndSub

******************************************************************************************************************
@SDESCRIPTION:AddstheDatabase-connectionobjecttothedebug-instance.TodisplayDatabase-information
@PARAM:-oSQLDB[object]:connection-object
******************************************************************************************************************
PublicSubGrabDatabaseInfo(byvaloSQLDB)
dbg_DB_Data=AddRow(dbg_DB_Data,ADOVer,oSQLDB.Version)
dbg_DB_Data=AddRow(dbg_DB_Data,OLEDBVer,oSQLDB.Properties(OLEDBVersion))
dbg_DB_Data=AddRow(dbg_DB_Data,DBMS,oSQLDB.Properties(DBMSName)&Ver:&oSQLDB.Properties(DBMSVersion))
dbg_DB_Data=AddRow(dbg_DB_Data,Provider,oSQLDB.Properties(ProviderName)&Ver:&oSQLDB.Properties(ProviderVersion))
EndSub

******************************************************************************************************************
*PrintDatabaseInfo
******************************************************************************************************************
PrivateSubPrintDatabaseInfo(byvalDivSetNo)
dimtbl
tbl=MakeTable(dbg_DB_Data)
tbl=replace(replace(replace(DivSets(DivSetNo),#sectname#,DATABASE),#title#,DATABASEINFO),#data#,tbl)
Response.Writereplace(tbl,,vbcrlf)
EndSub

******************************************************************************************************************
*PrintCollection
******************************************************************************************************************
PrivateSubPrintCollection(ByvalName,ByValCollection,ByValDivSetNo,ByValExtraInfo)
DimvItem,tbl,Temp
ForEachvItemInCollection
ifisobject(Collection(vItem))andName<>SERVERVARIABLESandName<>QUERYSTRINGandName<>FORMthen
tbl=AddRow(tbl,vItem,{object})
elseifisnull(Collection(vItem))then
tbl=AddRow(tbl,vItem,{null})
elseifisarray(Collection(vItem))then
tbl=AddRow(tbl,vItem,{array})
else
ifdbg_AllVarsthen
tbl=AddRow(tbl,<nobr>&vItem&</nobr>,server.HTMLEncode(Collection(vItem)))
elseif(Name=SERVERVARIABLESandvItem<>ALL_HTTPandvItem<>ALL_RAW)orName<>SERVERVARIABLESthen
ifCollection(vItem)<>then
tbl=AddRow(tbl,vItem,server.HTMLEncode(Collection(vItem)))&{&TypeName(Collection(vItem))&})
else
tbl=AddRow(tbl,vItem,...)
endif
endif
endif
Next
ifExtraInfo<>thentbl=tbl&<TR><TDCOLSPAN=2><HR></TR>&ExtraInfo
tbl=MakeTable(tbl)
ifCollection.count<=0thenDivSetNo=2
tbl=replace(replace(DivSets(DivSetNo),#title#,Name),#data#,tbl)
tbl=replace(tbl,#sectname#,replace(Name,,))
Response.Writereplace(tbl,,vbcrlf)
EndSub

******************************************************************************************************************
*AddRow
******************************************************************************************************************
PrivateFunctionAddRow(byvalt,byvalvar,byvalval)
t=t&<TRvalign=top><TD>&var&<TD>=&val&</TR>
AddRow=t
EndFunction

******************************************************************************************************************
*MakeTable
******************************************************************************************************************
PrivateFunctionMakeTable(byvaltdata)
tdata=<tableborder=0style=font-size:10pt;font-weight:normal;>+tdata+</Table>
MakeTable=tdata
EndFunction

******************************************************************************************************************
@SDESCRIPTION:DrawstheDebug-panel
******************************************************************************************************************
PublicSubdraw()
Ifdbg_EnabledThen
dbg_FinishTime=Now()

DimDivSet,x
DivSet=split(dbg_Show_default,,)
dbg_Show=split(dbg_Show,,)

Forx=0toubound(dbg_Show)
divSet(x)=dbg_Show(x)
Next

Response.Write<BR><Tablewidth=100%cellspacing=0border=0style=font-family:arial;font-size:9pt;font-weight:normal;><TR><TD><DIVstyle=background:#005A9E;color:white;padding:4;font-size:12pt;font-weight:bold;>Debugging-console:</DIV>
CallPrintSummaryInfo(divSet(0))
CallPrintCollection(VARIABLES,dbg_Data,divSet(1),)
CallPrintCollection(QUERYSTRING,Request.QueryString(),divSet(2),)
CallPrintCollection(FORM,Request.Form(),divSet(3),)
CallPrintCookiesInfo(divSet(4))
CallPrintCollection(SESSION,Session.Contents(),divSet(5),AddRow(AddRow(AddRow(,LocaleID,Session.LCID&(&H&Hex(Session.LCID)&)),CodePage,Session.CodePage),SessionID,Session.SessionID))
CallPrintCollection(APPLICATION,Application.Contents(),divSet(6),)
CallPrintCollection(SERVERVARIABLES,Request.ServerVariables(),divSet(7),AddRow(,Timeout,Server.ScriptTimeout))
CallPrintDatabaseInfo(divSet(8))
CallPrintCollection(SESSIONSTATICOBJECTS,Session.StaticObjects(),divSet(9),)
CallPrintCollection(APPLICATIONSTATICOBJECTS,Application.StaticObjects(),divSet(10),)
Response.Write</Table>
EndIf
EndSub

Destructor
PrivateSubClass_Terminate()
Setdbg_Data=Nothing
EndSub

EndClass

%>

类的说明:
CLASSdebuggingConsole
Version:1.2



PublicProperties
PropertyLetEnabled(bNewValue)[bool]Setsenabledtotrueorfalse
PropertyGetEnabled[bool]Getstheenabledvalue
PropertyLetShow(bNewValue)[string]Setsthedebuggingpanel.Whereeachdigitinthestringrepresentsadebuginformationpaneinorder(11ofthem).1=open,0=closed
PropertyGetShow[string]Getsthedebuggingpanel.
PropertyLetAllVars(bNewValue)[bool]Setswheatherallvariableswillbedisplayedornot.true/false
PropertyGetAllVars[bool]Getsifallvariableswillbedisplayed.

PublicMethods
publicsubPrint(label,output)
Addsavariabletothedebug-informations.
publicsubGrabDatabaseInfo(byvaloSQLDB)
AddstheDatabase-connectionobjecttothedebug-instance.TodisplayDatabase-information
publicsubdraw()
DrawstheDebug-panel

MethodsDetail

publicsubPrint(label,output)
Parameters:-label[string]:Descriptionofthevariable
-output[variable]:Thevariableitself

publicsubGrabDatabaseInfo(byvaloSQLDB)
Parameters:-oSQLDB[object]:connection-object


评论


亲,登录后才可以留言!