热门标签 | 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
推荐阅读
  • web.py开发web 第八章 Formalchemy 服务端验证方法
    本文介绍了在web.py开发中使用Formalchemy进行服务端表单数据验证的方法。以User表单为例,详细说明了对各字段的验证要求,包括必填、长度限制、唯一性等。同时介绍了如何自定义验证方法来实现验证唯一性和两个密码是否相等的功能。该文提供了相关代码示例。 ... [详细]
  • 本文介绍了如何使用php限制数据库插入的条数并显示每次插入数据库之间的数据数目,以及避免重复提交的方法。同时还介绍了如何限制某一个数据库用户的并发连接数,以及设置数据库的连接数和连接超时时间的方法。最后提供了一些关于浏览器在线用户数和数据库连接数量比例的参考值。 ... [详细]
  • MySQL数据库锁机制及其应用(数据库锁的概念)
    本文介绍了MySQL数据库锁机制及其应用。数据库锁是计算机协调多个进程或线程并发访问某一资源的机制,在数据库中,数据是一种供许多用户共享的资源,如何保证数据并发访问的一致性和有效性是数据库必须解决的问题。MySQL的锁机制相对简单,不同的存储引擎支持不同的锁机制,主要包括表级锁、行级锁和页面锁。本文详细介绍了MySQL表级锁的锁模式和特点,以及行级锁和页面锁的特点和应用场景。同时还讨论了锁冲突对数据库并发访问性能的影响。 ... [详细]
  • YOLOv7基于自己的数据集从零构建模型完整训练、推理计算超详细教程
    本文介绍了关于人工智能、神经网络和深度学习的知识点,并提供了YOLOv7基于自己的数据集从零构建模型完整训练、推理计算的详细教程。文章还提到了郑州最低生活保障的话题。对于从事目标检测任务的人来说,YOLO是一个熟悉的模型。文章还提到了yolov4和yolov6的相关内容,以及选择模型的优化思路。 ... [详细]
  • 推荐系统遇上深度学习(十七)详解推荐系统中的常用评测指标
    原创:石晓文小小挖掘机2018-06-18笔者是一个痴迷于挖掘数据中的价值的学习人,希望在平日的工作学习中,挖掘数据的价值, ... [详细]
  • MyBatis错题分析解析及注意事项
    本文对MyBatis的错题进行了分析和解析,同时介绍了使用MyBatis时需要注意的一些事项,如resultMap的使用、SqlSession和SqlSessionFactory的获取方式、动态SQL中的else元素和when元素的使用、resource属性和url属性的配置方式、typeAliases的使用方法等。同时还指出了在属性名与查询字段名不一致时需要使用resultMap进行结果映射,而不能使用resultType。 ... [详细]
  • 本文讨论了clone的fork与pthread_create创建线程的不同之处。进程是一个指令执行流及其执行环境,其执行环境是一个系统资源的集合。在调用系统调用fork创建一个进程时,子进程只是完全复制父进程的资源,这样得到的子进程独立于父进程,具有良好的并发性。但是二者之间的通讯需要通过专门的通讯机制,另外通过fork创建子进程系统开销很大。因此,在某些情况下,使用clone或pthread_create创建线程可能更加高效。 ... [详细]
  • Oracle seg,V$TEMPSEG_USAGE与Oracle排序的关系及使用方法
    本文介绍了Oracle seg,V$TEMPSEG_USAGE与Oracle排序之间的关系,V$TEMPSEG_USAGE是V_$SORT_USAGE的同义词,通过查询dba_objects和dba_synonyms视图可以了解到它们的详细信息。同时,还探讨了V$TEMPSEG_USAGE的使用方法。 ... [详细]
  • 本文介绍了在MySQL8.0中如何查看性能并解析SQL执行顺序。首先介绍了查询性能工具的开启方法,然后详细解析了SQL执行顺序中的每个步骤,包括from、on、join、where、group by、having、select distinct、union、order by和limit。同时还介绍了虚拟表的概念和生成过程。通过本文的解析,读者可以更好地理解MySQL8.0中的性能查看和SQL执行顺序。 ... [详细]
  • 预备知识可参考我整理的博客Windows编程之线程:https:www.cnblogs.comZhuSenlinp16662075.htmlWindows编程之线程同步:https ... [详细]
  • 本文介绍了Oracle存储过程的基本语法和写法示例,同时还介绍了已命名的系统异常的产生原因。 ... [详细]
  • 如何在php文件中添加图片?
    本文详细解答了如何在php文件中添加图片的问题,包括插入图片的代码、使用PHPword在载入模板中插入图片的方法,以及使用gd库生成不同类型的图像文件的示例。同时还介绍了如何生成一个正方形文件的步骤。希望对大家有所帮助。 ... [详细]
  • Android实战——jsoup实现网络爬虫,糗事百科项目的起步
    本文介绍了Android实战中使用jsoup实现网络爬虫的方法,以糗事百科项目为例。对于初学者来说,数据源的缺乏是做项目的最大烦恼之一。本文讲述了如何使用网络爬虫获取数据,并以糗事百科作为练手项目。同时,提到了使用jsoup需要结合前端基础知识,以及如果学过JS的话可以更轻松地使用该框架。 ... [详细]
  • .NetCoreWebApi生成Swagger接口文档的使用方法
    本文介绍了使用.NetCoreWebApi生成Swagger接口文档的方法,并详细说明了Swagger的定义和功能。通过使用Swagger,可以实现接口和服务的可视化,方便测试人员进行接口测试。同时,还提供了Github链接和具体的步骤,包括创建WebApi工程、引入swagger的包、配置XML文档文件和跨域处理。通过本文,读者可以了解到如何使用Swagger生成接口文档,并加深对Swagger的理解。 ... [详细]
  • PG12新增的VACUUM命令的SKIP_LOCKED选项
    PG12版本的VACUUM命令新增了SKIP_LOCKED选项,该选项使得vacuum命令在遇到被lock住的table时可以跳过并被视为成功执行。之前的版本中,vacuum命令会一直处于等待状态。本文还提到了PostgreSQL 12.1版本的相关信息。 ... [详细]
author-avatar
wepiehr
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有