Important alert: (current site time 7/15/2013 10:38:03 PM EDT)
 

VB icon

DebugASP

Email
Submitted on: 7/17/2001 12:33:25 PM
By: Joe Fiorini  
Level: Intermediate
User Rating: Unrated
Compatibility: ASP (Active Server Pages)
Views: 14237
 
     Are you getting sick of adding and deleting response.write statements to print variables? Have you ever wished you could just call a function to print out your ENTIRE Request collection, or even just the Form object? Then this code is for you!
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: DebugASP
' Description:Are you getting sick of adding and deleting response.write statements to print variables? Have you ever wished you could just call a function to print out your ENTIRE Request collection, or even just the Form object?
Then this code is for you!
' By: Joe Fiorini
'
' Inputs:PrintRequest:
 gObjectType-
enum for which object in the Request collection you want to process (should be self-explanatory)
PrintVar:
 value-
The value of the variable you are printing
 varName-
String containing the name of the variable you are printing
'
' Returns:All functions return an HTML formatted string which then may be used in a Response.Write statement.
'
' Assumes:You need to use a <!--#include file=debug.asp--> in your asp page, and then set the variable gbDebug to true. If you don't want it to print anymore, then set gbDebug to false.
'
' Side Effects:None that I am aware of
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=6777&lngWId=4'for details.'**************************************

<%
	dim gbDebug
	gbDebug = false
	const eOTForm = 1
	const eOTQueryString = 2
	const eOTBoth = 3
	
	function PrintRequest(gObjectType)
		if not gbDebug then exit function
		dim iMaxFieldIndex, iCurFieldIndex, iMaxValueIndex, iCurValueIndex, sRequestCollection, _
			sFormObject, sQueryStringObject
		iMaxFieldIndex = request.Form.Count
		iCurFieldIndex = 1
		iCurValueIndex = 1
		
		if iMaxFieldIndex = 0 then
			sFormObject = "<p>Form object is empty!</p>"
		else
			sFormObject = "<p>Listing of all " & iMaxFieldIndex & " variables in form object:</p>"
		end if
		
		sFormObject = sFormObject & "<ol>"
		for iCurFieldIndex = 1 to iMaxFieldIndex
			sFormObject = sFormObject & "<li>" & Server.HTMLEncode(Request.Form.Key(iCurFieldIndex))
			iMaxValueIndex = Request.Form(iCurFieldIndex).Count
			sFormObject = sFormObject & "<ol>"
			for iCurValueIndex = 1 to iMaxValueIndex
				sFormObject = sFormObject & "<li>" & Server.HTMLEncode(Request.Form.Item(iCurValueIndex))_
					& "</li>"
			next
			sFormObject = sFormObject & "</li>"
		next
		sFormObject = sFormObject & "</ol>"
			
		iMaxFieldIndex = Request.QueryString.Count
		iCurFieldIndex = 1
		iCurValueIndex = 1
		if iMaxFieldIndex = 0 then
			sQueryStringObject = "<p>QueryString object is empty!</p>"
		else
			sQueryStringObject = "<p>Listing of all " & iMaxFieldIndex & " variables in the Request collection</p>"
		end if		
		
		sQueryStringObject = sQueryStringObject & "<ol>"
		for iCurFieldIndex = 1 to iMaxFieldIndex
			sQueryStringObject = sQueryStringObject & "<li>" & Server.HTMLEncode(Request.QueryString.Key(iCurFieldIndex))
			iMaxValueIndex = Request.QueryString(iCurFieldIndex).Count
			sQueryStringObject = sQueryStringObject & "<ol>"
			for iCurValueIndex = 1 to iMaxValueIndex
				sQueryStringObject = sQueryStringObject & "<li>" & Server.HTMLEncode(Request.QueryString(iCurFieldIndex)(iCurValueIndex))_
					& "</li>"
			next
			sQueryStringObject = sQueryStringObject & "</ol>"
			sQueryStringObject = sQueryStringObject & "</li>"
		next
		sQueryStringObject = sQueryStringObject & "</ol>"
		if gObjectType = eOTForm then
			sRequestCollection = sRequestCollection & sFormObject
		elseif gObjectType = eOTQueryString then
			sRequestCollection = sRequestCollection & sQueryStringObject
		else
			sRequestCollection = sRequestCollection & sFormObject & sQueryStringObject
		end if
		
		PrintRequest = sRequestCollection
		
	end function
	
	function PrintVar(value, varName)
		if not gbDebug then exit function
		PrintVar = Server.HTMLEncode(varName) & " = " & Server.HTMLEncode(value) & "<br>"
	end function
	
	function PrintErrorCode()
		if not gbDebug then exit function
 	sErrorCode = "Database error #: " & err.number & "<BR>" & chr(13)
 	sErrorCode = sErrorCode & "Description: " & err.description & "<BR>" & chr(13)
 	PrintErrorCode = sErrorCode	
 end function
%>


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
7/18/2001 4:07:47 AMDJ

Response.Write Err.Description
(If this comment was disrespectful, please report it.)

 
7/18/2001 8:42:43 AMhoward edidin

Where is eOTBoth used? And shouldn't eOTForm = 1
eOTQueryString = 2
eOTBoth = 3
be set as constants. Otherwise you will get an error if you use option explicit on the page.
(If this comment was disrespectful, please report it.)

 
1/7/2002 9:27:23 AMMarcio Coelho

how can I call the PrintRequest(gObjectType) function and what the gObjectType is ?

Thanks in advance
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.