Search Search

#1 worldwide
FREE Coding Lessons

since 1996
   THE BEST WAY to learn ASP & Asp.net!
Advertise Here!
click for details
Credits Host:
DiscountASP.net
Server Admin:
The "Team"
Contact Info.
Charles M. Carroll

my Blog
[prev. Lesson]  Errors: Trapping EVERY Error
     [next Lesson]  Errors: DB Error Information Trapping

Easy Debugging of Variables by Charles Carroll

This page demonstrates how you can print several variables in one step without resorting to:
<%
    response.write "fname=<b>" & fname & "</b><br>"
    response.write "lname=<b>" & lname & "</b><br>"
    response.write "x=<b>" & x & "</b><br>"
    response.write "y=<b>" & y & "</b><br>"
%>

by taking advantage of VB Eval and encapsulating it into a subroutine to do all the work for you.

   filename=/learn/test/debug1.asp

<Test Script Below>


<%option explicit%>
<html><head>
<title>debug1.asp</title>
</head><body bgcolor="#FFFFFF">
<%
dim fname,lname,x,y,counter,mysample

fname="Jennifer" 
lname="Jones"
x=9
y=7

dim myarray(9)
for counter=0 to 8
    myarray(counter)=counter
next

set mysample=server.CreateObject("Scripting.Dictionary")
mysample.Add "haircolor", "brown" 
mysample.add "eyecolor" , "blue" 
mysample.add "dateofbirth", "5/13/64"

debug(true)
Call ShowVars("fname,lname,x,y")
Call ShowArray(myarray,"myarray")
Call ShowDictionary(mysample,"mysample")

set mysample = nothing

%>
</body></html>
<!--#include file="lib_debug1.asp"-->

The library that does the work:

   filename=/learn/test/lib_debug1.asp

<Test Script Below>


<%
dim lib_debug1

FUNCTION debug(parmStat)
    lib_debug1=parmStat
    debug=lib_debug1
END FUNCTION

SUB ShowVars(parmVars)
    If lib_debug1=false THEN
        exit sub
    END IF
    dim myparameters,parmcount,counter,thisvar,strexec,strall
    myparameters=SPLIT(parmVars,",")
    parmcount=ubound(myparameters)
    for counter=0 to parmcount
        thisvar=myparameters(counter)
        strexec=thisvar
        strexec=eval(strexec)
        strall=strall & "<b>" & thisvar & "</b>=" & strexec & "<br>"
    next
    response.write strall
END SUB

SUB ShowDictionary(parmdict,parmLabel)
    If lib_debug1=false THEN
        exit sub
    END IF
    DIM key
    response.write "Dictionary:" & parmLabel & "<br>"
    FOR EACH key IN parmdict
        response.write "&nbsp;&nbsp;&nbsp;" & parmLabel & ".item(""" & key & """)=<b>" & parmdict.item(key) & "</b><br>" 
    NEXT
    response.write "Dictionary display done:" & parmLabel & "<br>"
END SUB

SUB ShowArray(parmArray,parmLabel)
    If lib_debug1=false THEN
        exit sub
    END IF
    dim highcount, counter
    response.write "Array:" & parmLabel & "<br>"
    highcount=ubound(parmArray)
    response.write parmLabel & " ubound=" & highcount & "<br>"
    for counter=0 to highcount
      response.write "&nbsp;&nbsp;&nbsp;" & parmLabel & "(" & counter & ")</b>="
      response.write parmArray(counter) & "<br>"
   next
END SUB
%>

Chaz Wish List
Tall Tip $5
Grande Tip $20
Venti Tip $39
Tip Jar Thanks
2004 Thanks
2005 Thanks
HUGE Tip -love site