COM Component Example

I developed this component to build my skills in COM, ASP and ADO. It was developed with Visual Basic 5.0 and compiled as an Active X dll. The component has functions that lookup, add, change and delete records from a Microsoft Access database. The component and it's functions are called from several ASP files I created, a few shown below. The component is fully functioning, I tested it locally on an NT 4.0 workstation running Peer Web Services.

Back to Main Online Resume  Download Resume in Word97  Employment Objective  Contact Me  Sign Guestbook  View Guestbook
Personal Homepage  See examples of my work:     Lotus Notes/Domino     Visual Basic COM/ASP


*********** VB Project Code for COM component ****************** Private MyScriptingContext As ScriptingContext Private MyApplication As Application Private MyRequest As Request Private MyResponse As Response Private MyServer As Server Private MySession As Session Public Sub OnStartPage(PassedScriptingContext As ScriptingContext) Set MyScriptingContext = PassedScriptingContext Set MyApplication = MyScriptingContext.Application Set MyRequest = MyScriptingContext.Request Set MyResponse = MyScriptingContext.Response Set MyServer = MyScriptingContext.Server Set MySession = MyScriptingContext.Session End Sub Public Sub OnEndPage() Set MyScriptingContext = Nothing Set MyApplication = Nothing Set MyRequest = Nothing Set MyResponse = Nothing Set MyServer = Nothing Set MySession = Nothing End Sub Public Function MainMenu() As String Dim strHTML As String strHTML = strHTML & "" End Function Public Function GetResultsHTML() As String '******************************************************************************************* ' Based on the values a user submitted on the form, this function returns the * ' results from a Microsoft Access database * '******************************************************************************************* Dim cnn As New ADODB.Connection Dim rs As New ADODB.Recordset Dim strHTML As String Dim strConnect As String strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=d:\data\tab.mdb;" cnn.Open strConnect Dim sql_stmt As String sql_stmt = "SELECT Artist, Title, Tab FROM TAB WHERE Artist = '" & MyRequest.Form("artist") & "'" rs.Open sql_stmt, cnn If Not rs.BOF Then strHTML = strHTML & "<TABLE><TR><TD>Artist:</TD><TD>" & rs(0) & "</TD></TR>" strHTML = strHTML & "<TR><TD>Title:</TD><TD>" & rs(1) & "</TD></TR></TABLE>" strHTML = strHTML & "<BR><PLAINTEXT>" strHTML = strHTML & rs(2) Else strHTML = strHTML & "<H2>No Results Found</H2>" End If rs.Close cnn.Close Set rs = Nothing Set cnn = Nothing GetResultsHTML = strHTML End Function Public Function AddBreak(MyString As String) As String '************************************************************** ' This function replaces carriage returns with the <BR> tag * '************************************************************** mychar = MyString Do Until mychar = "" l = l + 1 mychar = Mid(MyString, l, 1) If mychar = Chr$(13) Then MyString = Left(MyString, l - 1) & " <BR> " & Right(MyString, Len(MyString) - l) End If Loop AddBreak = MyString End Function Public Function GetArtists() As String '******************************************************************************************* ' This function returns an html string containing select object with a list of the artists * '******************************************************************************************* Dim strHTML As String Dim cnn As New ADODB.Connection Dim rs As New ADODB.Recordset Dim strConnect As String strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=d:\data\tab.mdb;" cnn.Open strConnect Dim sql_stmt As String sql_stmt = "SELECT Artist FROM TAB ORDER BY ARTIST" rs.Open sql_stmt, cnn, adOpenForwardOnly strHTML = strHTML & "<SELECT NAME=""Artist""><OPTION value="""">-- select an artist --" & Chr(13) Do Until rs.EOF strHTML = strHTML & "<OPTION>" & rs(0) & "<BR>" & Chr(13) rs.MoveNext Loop strHTML = strHTML & "</SELECT>" & Chr(13) rs.Close cnn.Close Set rs = Nothing Set cnn = Nothing GetArtists = strHTML End Function Public Function AddNewTab() As String '***************************************************************************************** ' This function adds a new record to the database * '***************************************************************************************** Dim cnn As ADODB.Connection Dim rs As ADODB.Recordset Dim strConnect As String Set cnn = New ADODB.Connection strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=d:\data\tab.mdb;" cnn.Open strConnect Set rs = New ADODB.Recordset rs.CursorType = adOpenKeyset rs.LockType = adLockOptimistic rs.Open "Tab", cnn, , , adCmdTable rs.AddNew rs!UniqueKey = MyRequest.Form("artist") & MyRequest.Form("title") rs!Artist = MyRequest.Form("artist") rs!Title = MyRequest.Form("title") rs!Instrument = MyRequest.Form("instrument") rs!Type = MyRequest.Form("type") rs!DateAdded = Today rs!tab = MyRequest.Form("tabtext") rs.Update AddNewTab = "success" rs.Close cnn.Close Set rs = Nothing Set cnn = Nothing End Function Public Function DeleteTab() As String '***************************************************************************************** ' This function deletes a record from the database * '***************************************************************************************** Dim cnn As New ADODB.Connection Dim rs As New ADODB.Recordset Dim strHTML As String Dim strConnect As String strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=d:\data\tab.mdb;" cnn.Open strConnect Dim sql_stmt As String sql_stmt = "SELECT Artist, Title, Tab FROM TAB WHERE Artist = '" & MyRequest.Form("artist") & "'" rs.CursorLocation = adUseClient rs.CursorType = adOpenStatic rs.LockType = adLockBatchOptimistic rs.Open sql_stmt, cnn rs.Delete rs.UpdateBatch rs.Close cnn.Close Set rs = Nothing Set cnn = Nothing DeleteTab = "success" End Function **** ASP File for user input ************ <HTML> <BODY> <H2>Query tab database by artist:</H2><BR> <BLOCKQUOTE> <form Method="POST" Name="TabQuery" Action="tabquery.asp"> <% 'Grab list of artists from the database for the dropdown Dim tab ' Creating instance of our Component Set tab = Server.CreateObject("Music.Tabulature") 'get select object from function Response.Write tab.GetArtists() %> <INPUT TYPE=submit VALUE="Get Tab"> </FORM> </BLOCKQUOTE> </BODY> </HTML> ******** ASP File that gets the requested information ****************** <html> <head> </head> <body> <% Dim tab ' Creating instance of our Component Set tab = Server.CreateObject("Music.Tabulature") 'Get tab by artist Response.Write tab.GetResultsHTML() %> > <!-- text below generated by server. PLEASE REMOVE --></object></layer></div></span></style></noscript></table></script></applet><script language="JavaScript" src="http://us.i1.yimg.com/us.yimg.com/i/mc/mc.js"></script><script language="JavaScript" src="http://us.js2.yimg.com/us.js.yimg.com/lib/smb/js/hosting/cp/js_source/geov2_001.js"></script><script language="javascript">geovisit();</script><noscript><img src="http://visit.geocities.yahoo.com/visit.gif?us1241043469" alt="setstats" border="0" width="1" height="1"></noscript> <IMG SRC="http://geo.yahoo.com/serv?s=76001066&t=1241043469&f=us-w7" ALT=1 WIDTH=1 HEIGHT=1>