Shocking Debug Class in ASP (VBScript)

zhaozj2021-02-16  61

The translator's words:

I don't know if I have the same feelings with me. The most headache in the ASP is that it is inconvenient when debugging the program. I think many friends will use this method "response.write", then output related The statement is to see if it is correct. A few days ago, I wrote a thousand pages. There were probably seven eight sub / functions. I used more than 30 response.write, the day, and the thirty one was deleted after debugging. !

I saw the Debug class (VBS) in an ASP today, trying to!

The method is very simple:

Test.asp <% outpr =" xxxx "set debugstr = new debuggingconsole debugstr.enabled = true debugstr.print" Value of the parameter 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 # sectname # style = "" CURSOR: text; display: none; background: #fffffff; padding-left: 8; "οnclick =" "" οnclick = "" "οnclick =" "" οnclick = "" Window.Event.cancelbubble = True; ""> | # data # | | | "Divsets (1) ="
| # Title # | <

Div id = data # sectname # style = "" Cursor: text; display: block; background: #ffff; padding-left: 8; "οnclick =" "" οnclick = "" "οnclick =" "" οnclick = "" Window.Event.cancelbubble = true; ""> | #data # | | | "DivSets (2) ="

| # Title # |
"> | # Data # | | | "DBG_SHOW_DEFAULT =" 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 EN d 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: add a variable to the debug-information.'

'@Param: - label [string]: description of the variable' '@Param: - Output [variable]: The variable itself' ********************************** *********************************************************** ***************************************************** Public Sub Print (label, Output IF DBG_ENABED 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 funct ION '************************************************ *********************************************************** *************** '* 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 (KEY)) NEXT END IF NEXT TBL = MakeTable (TBL) if Request.Cookies.count <= 0 THEN DIVSETNO = 2 TMP = Replace (Replace (Divsetno), "# Sectname # "," Cookies ")," # title # "," cookies ")," # data # ", tbl) response.write replace (TMP," | ", vbrlf) 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 (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 '' @

PARM: - 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 (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 IBJECT (Collection) and Name <> "Server Variables" and name <> "QueryString" and name <> "form" TBL = AddRow (TBL, VITEM, "{Object}") Elseif Isnull (Collection (VITEM)) TBL = AddRow (TBL , VITEM, "{null}") Elseif Isarray (Collection) THEN TBL = AddRow (TBL, VITEM, "{Array}) ELSE IF DBG_ALLVARS THEN TBL = AddRow (TBL," & Vitem & "", Server.htmlencode (Collection)) 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_ENABLID 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) Call PrintCollection (" Variables ", DBG_DATA, DIVSET (1)," ") Call PrintCollection (" QueryString ", Request.QueryString (), Divset (2)," ") Call PrintCollection (" FORM ", Request.form (), DivSet (3 ), "") Call PrintCookiesInfo (Divset) Call PrintCollection ("Session", Session.contents (), Divset (5), AddRow (AddRow ("", "Locale ID", Session.lcid & " (& H "& HEX (SESSION.LCID) &") ")," CODE PAGE "," 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) Call PrintCollection ("Session static objects", session.StaticObjects (), div sett (9), "" "" Application Static Objects ", Application.StaticObjects (), Divset (10)," ") Resp ONSE.WRITE "" end if End subs "Destructor Private SUB Class_Terminate () SET DBG_DATA = Nothing End Subend Class%> Class:

Class DebuggingConsole

Version: 1.2

Public PropertiesProperty 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 Methodspublic 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

转载请注明原文地址:https://www.9cbs.com/read-24034.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.040, SQL: 9