|
Encapsulate Your Code in Reusable
Libraries
You should create many subroutines and functions
and instead of placing them in each page just use the include facility to access them. The
following scripts are very compact because they call SUBroutines that the include files
contain.
Here someone has encapsulated HTML coding into a high level
ASP call:
filename=/learn/test/htmldemo.asp
<!--#include virtual="/learn/test/lib_htmlstuff.asp"-->
<html><head>
<title>libhtmldemo.asp by Phil Paxton</title></head>
<body>
<form action="lib_htmldemorespond.asp">
<%
Call Form_TextBox("first name","Fname",20,20,"")
response.write "<br>"
Call Form_TextBox("Last Name","Lname",20,20,"")
response.write "<br>"
Call Form_TextBox("City","cy",20,20,"")
response.write "<br>"
Call Form_TextBox("State","st",2,2,"")
response.write "<br>"
Call Form_TextBox("Zip Code","zp",10,10,"")
response.write "<br>"
Call Form_SubmitButton("Register Me","register")
%>
</form>
</body>
</html>
Here displaying a listbox from a database has been simplified
by a subroutine:
filename=/learn/test/subdblist.asp
<html><head>
<TITLE>subdblist.asp</TITLE>
</head><body bgcolor="#FFFFFF">
<form>
<%
theDSN="DSN=student;uid=student;pwd=magic"
call query2list("city","publishers","cy",theDSN,"Rockville")
call query2list("state", "publishers","st",theDSN,"MD")
call query2list("zip", "publishers","zp",theDSN,"20851")
%>
</form>
<!--#include virtual="/learn/test/subdblist.inc"-->
</body></html>
The library files/includes that make all these tasks one step
are detailed at:
/freebook/asp/qualitycode.aspx
|