ASP – Writing Out Information During Debugging

Like many users of ASP I often use the Response Object Write Method to show the value of a variable during debugging.

e.g.

response.write(strSQL) ' write out value of an SQL string

However, on a “busy” page it’s not always easy to see the result of this action as the value written out gets lost in the rest of the text on the page.

Also, I’ll often write out an SQL string in this way which I then want to copy into a query to mess around with the results.

To get around this I wrote the following two functions.

The first (DW – short for DocumentWrite) relies on a variable called sysDebug being set to “TRUE” (as a string). I’ll often place the sysDebug declaration at the top of a main configuration page. When I want to debug my application I’ll set this variable to “TRUE” and the DW function will write out the values throughout my pages.

This then displays something similar to the following:

As an extension to this I also created the (imaginitively named) DW2 function.

This is similar to DW but does not use the sysDebug variable. This function is simply entered as and when required. I tend to use this to replace a standard response.write.

The DW2 function also provides a Copy To Clipboard button that will copy the contents of the debug box to the user’s clipboard.

This results in something like this:

The code for the two function is as follows:

' DW requires the sysDebug variable to be set as "TRUE" before output is shown
Function DW(myText)
dim BuildDebugLine
if sysDebug="TRUE" then
BuildDebugLine = "
<blockquote>"
BuildDebugLine= BuildDebugLine & "
<div style='border:1px solid #000000; bgcolor:#FFFFCC border-style: solid; padding-left: 4px; padding-right: 4px; padding-top: 4px; padding-bottom: 4px; background-color:#FFFF99; width:100%'><font size='2'><code>" & myText & "</code></font></div></blockquote>
"
response.write(BuildDebugLine)
end if
End Function

' DW2 does not use sysDebug variable and writes out value whenever called
Function DW2(myText)
dim BuildDebugLine
if myText="" then myText="[Empty String]"
if isnull(myText)="" then myText="[NULL]"
BuildDebugLine = "
<blockquote>"
BuildDebugLine= BuildDebugLine & "
<div style='border:1px solid #000000; bgcolor:#FFFFCC border-style: solid; padding-left: 4px; padding-right: 4px; padding-top: 4px; padding-bottom: 4px; background-color:#99FF99; width:100%'><font size='2'><code><span id='copytext'>" & myText & "</span></code>
"
BuildDebugLine= BuildDebugLine & "<TEXTAREA ID='holdtext' STYLE='display:none;'>"
BuildDebugLine= BuildDebugLine & "</TEXTAREA>"
BuildDebugLine= BuildDebugLine & "
<BUTTON onClick='ClipBoard();' style='font-family: Tahoma; font-size: 8pt'>Copy to Clipboard</BUTTON></font></div></blockquote>
"
response.write(BuildDebugLine)
End Function

Sorry about the layout of the code above. I’ll sort this out when I figure out how WordPress handles code!

Advertisements

0 Responses to “ASP – Writing Out Information During Debugging”



  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Blog Stats

  • 222,048 hits

Counter

ClustrMap


%d bloggers like this: