- 在线时间
- 0 小时
- 最后登录
- 2007-9-23
- 注册时间
- 2004-9-10
- 听众数
- 3
- 收听数
- 0
- 能力
- 0 分
- 体力
- 9975 点
- 威望
- 7 点
- 阅读权限
- 150
- 积分
- 4048
- 相册
- 0
- 日志
- 0
- 记录
- 0
- 帖子
- 1893
- 主题
- 823
- 精华
- 2
- 分享
- 0
- 好友
- 0

我的地盘我做主
该用户从未签到
 |
< >不知道用ASP写代码的朋友是不是和我有一样的感受,ASP中最头疼的就是调试程序的时候不方便,我想可能很多朋友都会用这样的方法“response.write ”,然后输出相关的语句来看看是否正确。前几天写了一个千行的页面,里面大概有七八个SUB/FUNCTION,调试的时候用了有三十几个response.write ,天,调试完后把这三十个一个个删除,累! </P>
, R5 S5 c5 o( W7 c& ~! I2 e< >今天看到一个ASP中的Debug类(VBS),试用了一下,绝! ( b6 X% ]6 A) Q% I; S5 }2 _
使用方法很简单: 7 c' H' G9 I* ?
test.asp </P>
: X5 u! g5 |4 d$ v/ F$ P5 l< ><!--#INCLUDE FILE="debuggingConsole.asp"-->
+ m) c) ~: p% D# B$ ^1 a) y4 p, f( D<% ) Z# ?9 u; l( x, T7 m( h
output="XXXX"
, H! j6 ]- [- b. C1 vSet debugstr = New debuggingConsole
, [# `2 j& i' A8 Pdebugstr.Enabled = true
7 E+ x, u, ] V8 n( c debugstr.Print "参数output的值", output
1 K% L! [ S h '…… + ?' }9 f0 V+ [; i' i* |
debugstr.draw
0 s$ W" u- I9 q+ _Set debugstr = Nothing
' e. T) Y9 g9 Y6 O6 Y%> </P>0 |* E% |2 b5 t v: w
< >=================================================== </P>
, ]( I, K3 i6 j. k* z< >debuggingConsole.asp </P>
$ O$ t5 U7 Q" ~: t4 p: A: v< ><% & ^2 d2 @+ e: X+ S& G+ y
Class debuggingConsole </P>
! R4 n u7 h+ ~" p1 m) N& a< > private dbg_Enabled 1 X( X4 g* s; ?* _ w, W3 t$ Z
private dbg_Show
2 `9 w+ V) C( O+ L! Y private dbg_RequestTime % a, g+ f ]$ u, r# {& n+ T
private dbg_FinishTime
' F. v4 q. `# P9 I a# E: f% `+ S private dbg_Data 0 l$ F2 a( K% z' R9 f
private dbg_DB_Data
) \ j( U6 o& p: E8 r {" |: B private dbg_AllVars 2 Q' t( T9 W- n g' l, a
private dbg_Show_default 5 v* ~& w. b" {* ^7 T
private DivSets(2)
# L/ y9 |) O, V) C# O
$ h, R4 S5 l5 _; o8 G c'Construktor => set the default values
6 C8 y- Z$ t" _+ x& m" wPrivate Sub Class_Initialize() & x7 Q+ X# I: J+ d- K$ G: r
dbg_RequestTime = Now() " N- [/ d; T5 U7 R
dbg_AllVars = false # t4 o& Y. g2 j
Set dbg_Data = Server.CreateObject("Scripting.Dictionary") </P>& L5 f* Z/ Y' N
< >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>|" </P>
- j; {/ W2 o* j5 J< > DivSets(1) = "<TR><TD># r/ ]+ L7 b: y7 [4 o, d3 b' M$ v
<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>|" </P>8 d3 G: m, @' c6 ?6 X+ M+ E
< > 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>|" </P>3 r1 s) X6 S' e% H
< > dbg_Show_default = "0,0,0,0,0,0,0,0,0,0,0" . H2 f2 U& Z) {% s
End Sub </P>
3 a+ c; i! [* f! k6 j< > ublic Property Let Enabled(bNewValue) ''[bool] Sets "enabled" to true or false 4 c$ S" ~+ H/ a p3 T' v
dbg_Enabled = bNewValue
; V$ s, a, n. \8 j, n2 P! p- {% yEnd Property </P>
5 P# u( \& V; y- K) j< > ublic Property Get Enabled ''[bool] Gets the "enabled" value
3 |6 g( N9 L0 F Enabled = dbg_Enabled : [. C& ?! T; \$ a0 w e
End Property </P>6 ~8 w: N3 P: M
< > ublic 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 * v" ]1 h, n% O+ l& @
dbg_Show = bNewValue 7 P9 s; f9 h/ w
End Property </P>
+ z) O4 v- B) C4 |! e< > ublic Property Get Show ''[string] Gets the debugging panel.
3 L! b5 @$ Y) Q4 v: U Show = dbg_Show 8 C. @- t" T! w" d- \8 C, k8 Q( L
End Property </P>5 T% V7 d. z# p* C. X' s/ U/ C
< > ublic Property Let AllVars(bNewValue) ''[bool] Sets wheather all variables will be displayed or not. true/false ; a4 ^, ]& \9 V, V- H& v
dbg_AllVars = bNewValue
$ r; Q8 g+ I. u1 t! zEnd Property </P>3 F+ }7 S# I% k3 C* k$ x/ v7 v
< > ublic Property Get AllVars ''[bool] Gets if all variables will be displayed. 2 _! a+ K9 W1 M W5 z
AllVars = dbg_AllVars
$ y( M# y) E8 a! ~: Q+ zEnd Property </P>+ Y" B/ S& F1 s- d- P
< >'*********************************************************** 3 W8 d9 s4 I& {" u2 T- @
''@SDESCRIPTION: Adds a variable to the debug-informations. , E0 C8 K- Z# [* f9 p2 d
''@PARAM: - label [string]: Description of the variable 8 D& b3 q. d) G
''@PARAM: - output [variable]: The variable itself
, N/ r& R. y1 T: m. U$ u'***********************************************************
9 C; W& U C* m& IPublic Sub Print(label, output) " @5 A% h3 @# H, e- z8 K2 n
If dbg_Enabled Then 3 B, a& P2 Y/ O P( @
if err.number > 0 then " y. W4 B# Q, e! R$ _7 a2 a
call dbg_Data.Add(ValidLabel(label), "!!! Error: " & err.number & " " & err.Description)
% S$ x/ ~3 B8 U g0 y err.Clear
4 M' l. J0 D. T else 7 ~9 E' Y2 e _5 M# q
uniqueID = ValidLabel(label) ) s' S2 ^% K: E; `. k
response.write uniqueID 1 D8 ?7 \! \2 e% p1 I
call dbg_Data.Add(uniqueID, output)
G9 x& g% ^5 y& V, K* s) ~ end if
2 A( V5 D- n# |2 p+ r End If
3 K! p0 ^4 n, T1 [' {( UEnd Sub
$ b! y' f) y, U, F5 y& P : T8 p' c5 A9 O, S1 [
'*********************************************************** # F7 m$ M8 w" u9 @
'* ValidLabel
; m3 C' I6 a1 ?. W6 z5 o8 s'***********************************************************
5 t$ }7 @/ Q4 D" }) d* uPrivate Function ValidLabel(byval label) 7 l8 H, K4 x3 `7 L' f
dim i, lbl - t1 w' a& I, y6 v, J: U6 z' {
i = 0
6 i9 @5 e- S3 r0 O; Z7 u lbl = label
: \3 E: ?1 p! r do ' q: S, g3 l( t
if not dbg_Data.Exists(lbl) then exit do
# a# v, S& I1 j i = i + 1 : [/ C- C3 `) L+ Y( J( n
lbl = label & "(" & i & ")" % t1 p. ], W" G0 f9 |+ _- C
loop until i = i
- {2 ^1 F# p" O" A$ [ [ R* Z4 L , _" w5 [- L0 d# `
ValidLabel = lbl
- E) ` {! ?; C; R$ G3 UEnd Function
! `& I0 J3 c" }6 P `+ J
1 s- ]; z! s' T, L# B/ K'***********************************************************
0 }& q7 |8 T! u% ]# ?, `; Y'* PrintCookiesInfo
8 q1 w1 z% f5 i'*********************************************************** + Q& P' H5 K$ g
Private Sub PrintCookiesInfo(byval DivSetNo) 3 {( |$ Z$ w8 z) {
dim tbl, cookie, key, tmp
) D$ \1 j2 A/ h! D7 D; A For Each cookie in Request.Cookies 4 H1 i# `, z- U: v1 f; C
If Not Request.Cookies(cookie).HasKeys Then * m7 T% [) h6 f# E
tbl = AddRow(tbl, cookie, Request.Cookies(cookie))
: E6 Z- K+ a v6 j2 { Else , A9 U6 A% O+ b6 y8 \
For Each key in Request.Cookies(cookie)
3 ~3 A& B# ^' P& ? D tbl = AddRow(tbl, cookie & "(" & key & ")", Request. 0 r3 U) |6 b& T3 ]+ f
Cookies(cookie)(key))
R0 h* X" c3 @, T' c Next
9 N+ z9 z( S! Z End If
X" E( U1 l+ g. \* e' t Next </P>3 Z7 B/ D+ E- w( m/ m) s
< > tbl = MakeTable(tbl)
3 d) `2 S4 r+ X. u if Request.Cookies.count <= 0 then DivSetNo = 2
6 z' ?0 J! j- j9 y tmp = replace(replace(replace(DivSets(DivSetNo),"#sectname#","COOKIES"),"#title#","COOKIES"),"#data#",tbl) 4 P' `" J H( t! n
Response.Write replace(tmp,"|", vbcrlf) % l1 u& A! f4 X4 _4 z; @0 m) H$ C5 t
end sub
/ G( `# i) K8 E6 r) s
& Z; v3 N% c' j- E2 s'***********************************************************
' Y; H0 W S# I& K0 L'* PrintSummaryInfo
7 L9 d$ ] t/ s+ X& ]% v: f( \'***********************************************************
& B- I3 _, d. T( yPrivate Sub PrintSummaryInfo(byval DivSetNo)
1 C* w/ B* j! A9 m1 [( | ?* e dim tmp, tbl
{3 c9 j& ~0 d* x5 a tbl = AddRow(tbl, "Time of Request",dbg_RequestTime) # x4 n3 M5 i4 Y, e% C
tbl = AddRow(tbl, "Elapsed Time",DateDiff("s", dbg_RequestTime, dbg_FinishTime) & " seconds")
& S& `- |, F" ~+ ?: f/ I' N tbl = AddRow(tbl, "Request Type",Request.ServerVariables("REQUEST_METHOD")) / j! g+ q- v. M
tbl = AddRow(tbl, "Status Code",Response.Status) ; w7 _! I3 b9 U j: n) D4 {
tbl = AddRow(tbl, "Script Engine",ScriptEngine & " " & ScriptEngineMajorVersion & "." & ScriptEngineMinorVersion & "." & ScriptEngineBuildVersion)
+ B) x4 l: m4 k; K4 z tbl = MakeTable(tbl)
o3 H! W1 O. W1 y tmp = replace(replace(replace(DivSets(DivSetNo),"#sectname#","SUMMARY"),"#title#","SUMMARY INFO"),"#data#",tbl)
5 U$ Y& S* u# {3 W; A Response.Write replace(tmp,"|", vbcrlf)
& H* N- g3 H" k5 \# n8 fEnd Sub </P>9 U$ b, o8 U/ H' B0 r- i& L
< >'***********************************************************
, m7 T8 M, Z& C! o' F% I''@SDESCRIPTION: Adds the Database-connection object to the debug-instance. To display Database-information
$ l& m: p, R7 @4 A; z; J! N''@PARAM: - oSQLDB [object]: connection-object , p- s6 o9 R7 A* F
'***********************************************************
; K7 C2 `# d4 x1 X; @' b. PPublic Sub GrabDatabaseInfo(byval oSQLDB) ) V ~1 | h$ x
dbg_DB_Data = AddRow(dbg_DB_Data, "ADO Ver",oSQLDB.Version) # y& _5 d* z2 \. ~, O- x) E
dbg_DB_Data = AddRow(dbg_DB_Data, "OLEDB Ver",oSQLDB.Properties("OLE DB Version"))
. S& e: F9 \& h$ F8 C+ p dbg_DB_Data = AddRow</P> |
zan
|