以下是引用片段: Public objContext As ObjectContext Public Application As ASPTypeLibrary.Application Public Server As ASPTypeLibrary.Server Public Session As ASPTypeLibrary.Session Public Response As ASPTypeLibrary.Response Public Request As ASPTypeLibrary.Request Class1.cls中的代码: Private Sub Class_Initialize() On Error Resume Next Set objContext = GetObjectContext Set Application = objContext.Item("Application") Set Server = objContext.Item("Server") Set Session = objContext.Item("Session") Set Request = objContext.Item("Request") Set Response = objContext.Item("Response") End Sub Private Sub Class_Terminate() On Error Resume Next Set Application = Nothing Set Server = Nothing Set Session = Nothing Set Request = Nothing Set Response = Nothing Set objContext = Nothing End Sub Public Sub AspClassInit() On Error GoTo Err Set conn = Server.CreateObject("ADODB.Connection") strcon = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" & Server.MapPath("Article.mdb") conn.Open strcon Set rs = Server.CreateObject("ADODB.Recordset") sql = "select * from Article order by ArticleID desc" rs.Open sql, conn, 1, 1 Response.Write "<html>" & vbCrLf Response.Write "<head>" & vbCrLf Response.Write "<meta http-equiv=""Content-Type"" content=""text/html; charset=gb2312"">" & vbCrLf Response.Write "<title>文章管理系统-CSSTUDIO</title>" & vbCrLf Response.Write "</head>" & vbCrLf Response.Write "<body bgcolor=""#FFFFFF"" topmargin=""0"">" & vbCrLf Response.Write "<table width=""100%"" border=""0"" cellpadding=""2"" cellspacing=""0"">" & vbCrLf Response.Write " <tr>" & vbCrLf Response.Write " <td width=""742"" height=""20"">文章标题</td>" & vbCrLf Response.Write " <td width=""90"">点击</td>" & vbCrLf Response.Write " <td width=""145"">添加日期</td>" & vbCrLf Response.Write " </tr>" & vbCrLf Response.Write "</table>" & vbCrLf While Not rs.EOF And Rows < rs.PageSize Response.Write "<table width=""100%"" border=""0"" cellspacing=""0"" cellpadding=""0"">" & vbCrLf Response.Write " <tr>" & vbCrLf Response.Write " <td width=""747"" height=""20"">☆<a href=""view.asp?id=" Response.Write rs("ArticleID") Response.Write """>" & vbCrLf Response.Write " " Response.Write rs("标题") Response.Write "</a></td>" & vbCrLf Response.Write " <td width=""94"">" Response.Write rs("点击") Response.Write "</td>" & vbCrLf Response.Write " <td width=""148"">" Response.Write rs("添加日期") Response.Write "</td>" & vbCrLf Response.Write " </tr>" & vbCrLf Response.Write "</table>" & vbCrLf rs.MoveNext Wend Response.Write "</body>" & vbCrLf Response.Write "</html>" & vbCrLf rs.Close Set rs = Nothing conn.Close Set conn = Nothing Exit Sub Err: If Err.Number = -13572468 Then Exit Sub Resume Next End Sub |
使用article.dll后的index.asp中的代码:
以下是引用片段: <%Dim AspTransBuilderObject Set AspTransBuilderObject = Server.CreateObject("article.Class1") AspTransBuilderObject.AspClassInit Set AspTransBuilderObject = Nothing%> |
以下是引用片段: <% Set conn=Server.CreateObject("ADODB.Connection") strcon = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" & Server.MapPath("Article.mdb") conn.Open strcon %> <% Set rs = Server.CreateObject ("ADODB.Recordset") sql="select * from Article order by ArticleID desc" rs.Open sql, Conn,1,1 %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>文章管理系统-CSSTUDIO</title> </head> <body bgcolor="#FFFFFF" topmargin="0"> <table width="100%" border="0" cellpadding="2" cellspacing="0"> <tr> <td width="742" height="20">文章标题</td> <td width="90">点击</td> <td width="145">添加日期</td> </tr> </table> <% While Not Rs.Eof And Rows<Rs.PageSize %> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="747" height="20">☆<a href="view.asp?id=<% = rs("ArticleID") %>"> <% =rs("标题") %></a></td> <td width="94"><% = rs("点击") %></td> <td width="148"><% = rs("添加日期") %></td> </tr> </table> <% Rs.MoveNext Wend %> </body> </html> <% rs.close set rs=nothing conn.close set conn=nothing %> |
四、结论
因为这些代码是在服务器端运行的,所以客户端不需要安装任何东西。这仅仅是用ActiveX DLL所能实现的功能的小小的例子。你们可以写好自己的更大的组件,而且还可以用VB中的很多控件。让我们用组件来扩展我们的程序的功能吧!也希望多多的看到我们中国人的组件。但愿本文能起到抛砖引玉的作用。
新闻热点
疑难解答