Open VB6, create a new ActiveX DLL
2. Add Microsoft Active Server Pages Object Library selection in project references
3, fill in the code as follows:
Copy Code code as follows:
' Code Start
' Declaration section
Private Myscriptingcontext as ScriptingContext
Private MyApplication as Application
Private Myrequest as Request
Private Myresponse as Response
Private MyServer as Server
Private MySession as session
' Definition of common functions (in VB to access ASP objects, that is, in VB can be equated with MyApplication in ASP application, Myrequest equivalent to the ASP in the request, Myresponse equivalent to ASP in the response, MyServer equivalent to the ASP in the server, mysession equivalent to the ASP in the session use)
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
' Create a custom function SayHello
Public Sub SayHello ()
Myresponse.write ("Hello World")
End Sub
' Code End
4. Change the class name to read: HelloWorld the project name to: Testvbcode
5, Generate TestVBCode.DLL files, and use the Windows Run Registration Component Command REGSVR32 path \testvbcode.dll registration can be used. (Uninstall Component command for regsvr32/u path \testvbcode.dll)
6, the establishment of test.asp files, code as follows
Copy Code code as follows:
<%
' VB self-constructing function call format
' Set object name =server.createobject (' project name. Class Name ')
' Object name. Name of the self-created function
Set mytestobj = Server.CreateObject ("Testvbcode.helloworld")
Mytestobj.sayhello
%>
7. The results of running the test.asp file are shown as follows:
Hello World
===========================================================
For more complex applications, you can extend this example to the outside.
Such as:
Copy Code code as follows:
Public Sub CONNSTR2 ()
Set conn = Myserver.createobject ("ADODB. Connection ")
Conn. Open "Driver={microsoft Access driver (*.mdb)};d bq=" & Myserver.mappath ("Codata.mdb")
Set RS = conn. Execute ("SELECT * FROM News")
Do but not Rs. Eof
Myresponse.write (RS ("News_title") & "<br>")
Rs. MoveNext
Loop
Rs. Close
Set conn = Nothing
End Sub
This is a database-connected code encapsulation, of course, here to add ADO reference.