While ASP.NET has some built in tools to aid in debugging, classic ASP is relatively
lacking in that regard. This tip will show you an easy way to check the values of your
application's variables and then stop execution before you do any database writes or
anything else you might not want to do while testing.
This tip comes from one of our readers. Here's his email:
Hi,
[I've been using this method to do some basic debugging and thought I would share it, as]
I am sure someone will find it helpful.
I use the Break("Line 101: " & strTestVariableValue) to show me the output and then stop without
doing anything else after it was called.
I then replace the "Break" with "Print" and move on to the next variable I would like to test.
It is very helpful when you do not want execute SQL commands lower down on your page while
debugging your code because execution stops after the Break() function is called.
<%
' DEBUG: output, continue...
Function Print(n)
Response.Write("<pre>" & n & "</pre>")
Response.Flush()
End Function
' DEBUG: output, stop!
Function Break(n)
Response.Write("<pre>" & n & "</pre>")
Response.Flush()
Response.End()
End Function
%>
This type of thing is perfect for echoing out a SQL query to be sure it's correct
and then stopping the script before it actually sends the query to the database and does any damage.
After all, one mistake in a DELETE statement and things can get ugly!
If you prefer, you can rename the functions to something like Trace (so they're closer to the ASP.NET syntax)
or whatever names you like, but regardless of what you call them, these two little functions
provide a quick and easy way to do some basic debugging when things don't go as planned.
Thanks go out to Hans Mussmann for sending us this tip!
If you have a tip you would like to submit, please send it to:
webmaster@asp101.com.