热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

asp:debug类调试程序

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

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

使用方法很简单:

test.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) = "|#title#| |#data#| 
|
|"
DivSets(1) = "|#title#| |#data#| 
||"
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), "!!! 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 "
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
推荐阅读
  • 成功安装Sabayon Linux在thinkpad X60上的经验分享
    本文分享了作者在国庆期间在thinkpad X60上成功安装Sabayon Linux的经验。通过修改CHOST和执行emerge命令,作者顺利完成了安装过程。Sabayon Linux是一个基于Gentoo Linux的发行版,可以将电脑快速转变为一个功能强大的系统。除了作为一个live DVD使用外,Sabayon Linux还可以被安装在硬盘上,方便用户使用。 ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • 本文讨论了一个数列求和问题,该数列按照一定规律生成。通过观察数列的规律,我们可以得出求解该问题的算法。具体算法为计算前n项i*f[i]的和,其中f[i]表示数列中有i个数字。根据参考的思路,我们可以将算法的时间复杂度控制在O(n),即计算到5e5即可满足1e9的要求。 ... [详细]
  • 如何实现织梦DedeCms全站伪静态
    本文介绍了如何通过修改织梦DedeCms源代码来实现全站伪静态,以提高管理和SEO效果。全站伪静态可以避免重复URL的问题,同时通过使用mod_rewrite伪静态模块和.htaccess正则表达式,可以更好地适应搜索引擎的需求。文章还提到了一些相关的技术和工具,如Ubuntu、qt编程、tomcat端口、爬虫、php request根目录等。 ... [详细]
  • 本文介绍了lua语言中闭包的特性及其在模式匹配、日期处理、编译和模块化等方面的应用。lua中的闭包是严格遵循词法定界的第一类值,函数可以作为变量自由传递,也可以作为参数传递给其他函数。这些特性使得lua语言具有极大的灵活性,为程序开发带来了便利。 ... [详细]
  • GetWindowLong函数
    今天在看一个代码里头写了GetWindowLong(hwnd,0),我当时就有点费解,靠,上网搜索函数原型说明,死活找不到第 ... [详细]
  • Spring源码解密之默认标签的解析方式分析
    本文分析了Spring源码解密中默认标签的解析方式。通过对命名空间的判断,区分默认命名空间和自定义命名空间,并采用不同的解析方式。其中,bean标签的解析最为复杂和重要。 ... [详细]
  • VScode格式化文档换行或不换行的设置方法
    本文介绍了在VScode中设置格式化文档换行或不换行的方法,包括使用插件和修改settings.json文件的内容。详细步骤为:找到settings.json文件,将其中的代码替换为指定的代码。 ... [详细]
  • 本文介绍了数据库的存储结构及其重要性,强调了关系数据库范例中将逻辑存储与物理存储分开的必要性。通过逻辑结构和物理结构的分离,可以实现对物理存储的重新组织和数据库的迁移,而应用程序不会察觉到任何更改。文章还展示了Oracle数据库的逻辑结构和物理结构,并介绍了表空间的概念和作用。 ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • 动态规划算法的基本步骤及最长递增子序列问题详解
    本文详细介绍了动态规划算法的基本步骤,包括划分阶段、选择状态、决策和状态转移方程,并以最长递增子序列问题为例进行了详细解析。动态规划算法的有效性依赖于问题本身所具有的最优子结构性质和子问题重叠性质。通过将子问题的解保存在一个表中,在以后尽可能多地利用这些子问题的解,从而提高算法的效率。 ... [详细]
  • Ubuntu 9.04中安装谷歌Chromium浏览器及使用体验[图文]
    nsitionalENhttp:www.w3.orgTRxhtml1DTDxhtml1-transitional.dtd ... [详细]
  • C++字符字符串处理及字符集编码方案
    本文介绍了C++中字符字符串处理的问题,并详细解释了字符集编码方案,包括UNICODE、Windows apps采用的UTF-16编码、ASCII、SBCS和DBCS编码方案。同时说明了ANSI C标准和Windows中的字符/字符串数据类型实现。文章还提到了在编译时需要定义UNICODE宏以支持unicode编码,否则将使用windows code page编译。最后,给出了相关的头文件和数据类型定义。 ... [详细]
  • 开发笔记:实验7的文件读写操作
    本文介绍了使用C++的ofstream和ifstream类进行文件读写操作的方法,包括创建文件、写入文件和读取文件的过程。同时还介绍了如何判断文件是否成功打开和关闭文件的方法。通过本文的学习,读者可以了解如何在C++中进行文件读写操作。 ... [详细]
  • 李逍遥寻找仙药的迷阵之旅
    本文讲述了少年李逍遥为了救治婶婶的病情,前往仙灵岛寻找仙药的故事。他需要穿越一个由M×N个方格组成的迷阵,有些方格内有怪物,有些方格是安全的。李逍遥需要避开有怪物的方格,并经过最少的方格,找到仙药。在寻找的过程中,他还会遇到神秘人物。本文提供了一个迷阵样例及李逍遥找到仙药的路线。 ... [详细]
author-avatar
菜123
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有