Quick Debug Beta 1

Search

 by Remas Wojciechowski

When it comes to debugging ASP, you often want to keep track of the variable values throughout the script. This article introduces a procedure that, when invoked, displays all variables in a script along with their values and internal types.

Scenario

Let's assume our ASP to be debugged (host.asp) looks like this:.

host.asp
<!-- #include file="debug.asp" -->
<%
Dim strA
Dim strB

strA = 7
' strX = 6
strB = 3
strC = "abc"

Call QDebug()

%>

The Procedure

As you can see, it first includes the file debug.asp and the calls the procedure QDebug. Here are the contents of debug.asp

debug.asp
<!-- #include file="_fn_file.asp" -->
<%
Sub QDebug()

  On Error Resume Next

  Dim strVPath_ThisFile
  Dim strPPath_ThisFile
  Dim strSourceCode
  Dim objRegExp
  Dim colMatches

  strVPath_ThisFile = Request.ServerVariables("SCRIPT_NAME")
  strPPath_ThisFile = Server.MapPath(strVPath_ThisFile)

  strSourceCode = File_ContentsToString(strPPath_ThisFile)

  Set objRegExp = New RegExp
  objRegExp.MultiLine = True
  objRegExp.Global = True
  objRegExp.Pattern = "^[ \f\t\v]*?([a-zA-Z][^'\. \f\t\v]*?)[ \f\t\v]="
  Set colMatches = objRegExp.Execute(strSourceCode)

  Response.Write("<table border=""1"">")

  For Each objItem In colMatches
    strVariableName = objItem.Submatches(0)
    strVariableType = TypeName(Eval(strVariableName))
    strVariableValue = Eval(strVariableName)
    Response.Write("<tr><td>" & Server.HTMLEncode(strVariableType) & "</td><td>" &   Server.HTMLEncode(strVariableName) & "</td><td>" & Server.HTMLEncode(strVariableValue) & "</td></tr>")
  Next

  Response.Write("</table>")

  Set objRegExp = Nothing

End Sub
%>

Note that the procedure QDebug utilizes the File_ContentsToString function, which--nomen omen--returns the contents of a given file as a string. You can download this function from my library: http://www.aspalliance.com/remas/Library/GetFileContents/.

Result

Finally, here's the output that QDebug generates:

IntegerstrA7
IntegerstrB3
StringstrCabc
This article was inspired by Charles Charroll's debugging idea.