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

Subroutines Db2list "Best" Approach  by Charles Carroll

Subroutines could be considerably more useful if they took optional parameters. Since they don't we can jury rig a system whereby a subroutine is invoked with two parameters: a delimiter and a string. And the string itself contains the various parameters. This approach implements a more optional parameter "like" solution.

   filename=/learn/test/subdblistbest.asp

<Test Script Below>


<html><head>
<TITLE>subdblistbest.asp</TITLE>
</head><body bgcolor="#FFFFFF">
<form>
<%call db2list("^","select distinct city from publishers^city^New York")%>
<%call db2list("^","select distinct state from publishers^state^NY^table^DSN=student;uid=student;pwd=magic")%>
<%call db2list("^","select distinct zip from publishers^Zip Code^^table")%>
</form>
<!--#include virtual="/learn/test/lib_dblistbest.asp"-->

The include file lib_dblistbest.asp looks like:

   filename=/learn/test/lib_dblistbest.asp

<Test Script Below>


<%
sub db2list(mydelim,myparm)

dim myparameters
myparameters=SPLIT(myparm,mydelim)
parmcount=ubound(myparameters)
myquery=myparameters(0)
label=myparameters(1)
default=myparameters(2)
if parmcount>2 then
    format=lcase(myparameters(3))
end if
if parmcount>3 then
    connstring=myparameters(4)
else
    connstring="DSN=Student;uid=student;pwd=magic"
end if

set conntemp=server.createobject("adodb.connection")
conntemp.open connstring
set rstemp=conntemp.execute(myquery)
If format="table" then%>
    <table width="100%" border="0" cellspacing="1"><td>
<%end if 
response.write label
If format="table" then%>
    </td><td>
<%end if%>
<Select>
<option value="<%=default%>" selected><%=default%></option>
<%
do while not rstemp.eof %>
    <option><%=RStemp(0)%></option>
<%
rstemp.movenext
loop
conntemp.close
%>
</select>
<%If format="table" then%>
    </td><tr></table>
<%end if
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