Page 3 - Discuss Debugging techniques in the ASP Development forum on ASP Free. Debugging techniques ASP Development forum discussing ASP related topics including coding practices, ASP tips, and more. Active Server Pages (ASP) enables you to empower your HTML pages dynamically with robust scripting options.
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
Posts: 5,385
Time spent in forums: 3 Weeks 4 Days 6 h 17 m 7 sec
Reputation Power: 1252
Quote:
Originally Posted by jmurrayhead
Something that hasn't been mentioned in this thread and that I see a lot of with new developers is unformatted code. Take these two samples for instance:
Code:
<%@ Language=VBScript %>
<%
set conn = Server.CreateObject("ADODB.Connection")
conn.Open "DSN=AdvWorks"
set rs = Server.CreateObject("ADODB.Recordset")
rs.CursorLocation = 3 ' adUseClient
rs.Open "Select * from Employees", conn
rs.PageSize = 2
intPageCount = rs.PageCount
Select Case Request("Action")
case "<<"
intpage = 1
case "<"
intpage = Request("intpage")-1
if intpage < 1 then intpage = 1
case ">"
intpage = Request("intpage")+1
if intpage > intPageCount then intpage = IntPageCount
Case ">>"
intpage = intPageCount
case else
intpage = 1
end select
%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE>ASP & ADO Paging</TITLE>
</HEAD>
<BODY bgColor=White text=Black>
<%
rs.AbsolutePage = intPage
For intRecord = 1 To rs.PageSize
Response.Write "Record number: " & intRecord & " "
Response.Write rs.Fields("FirstName") & " "
Response.Write rs.Fields("LastName") & "<br>"
rs.MoveNext
If rs.EOF Then Exit For
Next
rs.Close
set rs = Nothing
conn.Close
set conn = nothing
%>
<form name="MovePage" action="default.asp" method="post">
<input type="hidden" name="intpage" value="<%=intpage%>">
<input type="submit" name="action" value="<<">
<input type="submit" name="action" value="<">
<input type="submit" name="action" value=">">
<input type="submit" name="action" value=">>">
Page: <%=Intpage & " of " & intpagecount%>
</form>
</BODY>
</HTML>
Code:
<%@ EnableSessionState=False Language=VBScript %>
<%
set conn = Server.CreateObject("ADODB.Connection")
conn.Open "DSN=AdvWorks"
set rs = Server.CreateObject("ADODB.Recordset")
rs.CursorLocation = 3 ' adUseClient
rs.Open "Select * from Employees", conn
rs.PageSize = 2
intPageCount = rs.PageCount
Select Case Request("Action")
case "<<"
intpage = 1
case "<"
intpage = Request("intpage")-1
if intpage < 1 then intpage = 1
case ">"
intpage = Request("intpage")+1
if intpage > intPageCount then intpage = IntPageCount
Case ">>"
intpage = intPageCount
case else
intpage = 1
end select
%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE>ASP & ADO Paging</TITLE>
</HEAD>
<BODY bgColor=White text=Black>
<%
rs.AbsolutePage = intPage
For intRecord = 1 To rs.PageSize
Response.Write "Record number: " & intRecord & " "
Response.Write rs.Fields("FirstName") & " "
Response.Write rs.Fields("LastName") & "<br>"
rs.MoveNext
If rs.EOF Then Exit For
Next
rs.Close
set rs = Nothing
conn.Close
set conn = nothing
%>
<form name="MovePage" action="default.asp" method="post">
<input type="hidden" name="intpage" value="<%=intpage%>">
<input type="submit" name="action" value="<<">
<input type="submit" name="action" value="<">
<input type="submit" name="action" value=">">
<input type="submit" name="action" value=">>">
Page: <%=Intpage & " of " & intpagecount%>
</form>
</BODY>
</HTML>
Which one is easier to read? I hope you say the one on the bottom. When debugging code, having some type of formatted code (using indents, spaces, etc.) makes debugging much easier because the page is easier to read. Think about the first code sample above if it were a much larger application. Even if you have an editor that shows each line and an error shows the exact line..having formatted text still makes it much easier to debug.
Excellent point!!!
__________________
I would rather know than not know at all...