In the ASP version, our code was in the particular ASP page.  For the DLL, all code will be in the single DLL.  We will create a separate function for each page to call.  Each function will contain the code from the ASP page, with some differences:

VB supports data typing, so your variable declarations should include the data type.
We need to handle arguments in the type they arrive, array or not.
We will use "New" instead of "Server.CreateObject" to create our objects
We need to return an array or integer back.

All the code for my Addresses example can be found in Addresses.cls.

The first thing you should notice about the code:  All functions are using the same variables, so I declared them as Module-Level variables in the General Declarations section.  Note also that strDSN is declared as a constant.

View List
[
] Take a look at the GetAddresses function. Identify how the bullet points above are incorporated into the code. Also: The function requires no arguments The function returns a Variant data type. A Variant will store any data type. This allows me to return an array of data, if it exists. ASP uses Variants for all variables. The HTML table rows are not generated here. Instead, if there are table rows, I use the GetRows function of the RecordSet. GetRows converts the RecordSet into a two-dimensional array. It is VERY fast, faster than looping through the RecordSet. If there are no table rows, I return a String message. [
] View Details, Edit Details [
] Both of these pages are simply displaying the same information in either a read-only or editable mode. Take a look at the GetAddress function. Identify how all bullet points above are incorporated into the code. Also: AddressID is a number, but I still pass it and treat it as a String. I pass it as a String to the function because that is the way ASP gets it from the Form or QueryString collection. There is no point in having ASP try to cast it to a number. The AddressID is being concatentated into an SQL String, so again there is no point in casting it to a number. SQL will know how to treat the value. Since I have not placed quote marks around the value, SQL will treat it as a number. [
] UpdateDetails [
] Take a look at the UpdateAddress function. Identify how all bullet points above are incorporated into the code. Also: I could have passed in an array as an argument, as discussed in a previous lecture. Instead, I pass in the SQL string to execute. The reason I did it this way is because I would still have to write code in ASP to create the array and store the form field values. The amount of code would be about the same for ASP, but then the DLL would have additional processing to do on the array. The line of least work is to let the ASP create the SQL string and pass it to the DLL. [
]