Page

9.3.4- Use Subprocedures

Created by Brendan Doss.
Last Updated by Jim Minatel.  

PublicCategorized as 09. Error Handling.

Not yet tagged
<< 9.3.3- Use Option ExplicitChapter99.3.5- Use Include Files >>

Use Subprocedures

We introduced procedures in Chapter 5 and have already applied them to several of our examples. What you may not have realized is how useful they can be in optimizing your code. As you start writing more and more ASP code you'll find that you're using lots of similar routines in many of your pages, and possibly even several times in the same page. Instead of repeating this code you can put it into a sub procedure and then just call this procedure:

 

<%

' get the Form details

 

Call ProcessFormDetails (strName, strEmail)

 

' some processing

 

Call ProcessFormDetails(strName, strEmail)

 

 

Sub ProcessFormDetails (strN, strE)

' do some processing here

End Sub

 

%>

 

Now the processing of the form details is only done in one place, and if anything is wrong you only need to look for errors in one place. You can combine this with the trace statements too:

 

Sub ProcessFormDetails (strN, strE)

Response.Write "Debug: ProcessFormDetails Started<BR>"

 

' do some processing here

 

Response.Write "Debug: ProcessFormDetails Ended<BR>"

End Sub

 

This allows you to see when a sub procedure started and ended. You could even take this one step further and create some debugging and tracing routines:

 

Sub Trace (strString)

 

Response.Write "Debug: " & strString & "<BR>"

 

End Sub

 

Your procedure to process the form details would now look like this:

 

Sub ProcessFormDetails (strN, strE)

Trace "ProcessFormDetails Started"


' do some processing here

 

Trace "ProcessFormDetails Ended"

End Sub

 

This makes it even easier to see what's going on.

<< 9.3.3- Use Option ExplicitChapter99.3.5- Use Include Files >>

Copyright © 2003 by Wiley Publishing, Inc.

Powered by Near-TimeTerms of Services | Privacy Policy | Security Policy |