A long time ago, I sorted out the documents and reviewed them.
Use VB to encapsulate ASP and create a SayHello Test Program
1. Open VB6 and create ActiveX DLL
2. Add Microsoft Active Server Pages Object Library selection to the project reference
3. Add the following code:
'Code Start
'Declaration part
Private MyScriptingContext As ScriptingContext
Private MyApplication As Application
Private MyRequest As Request
Private MyResponse As Response
Private MyServer As Server
Private MySession As Session
'The following defines public functions (accessing ASP objects in VB, in VB, MyApplication can be equivalent to Application in ASP. MyRequest is equivalent to Request in ASP. MyResponse is equivalent to Response in ASP. MyServer is equivalent to Server in ASP. MySession is equivalent to Session in ASP. 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 user-defined function SayHello
Public Sub SayHello ()
MyResponse. Write ("Hello World ")
End Sub
'Code End
4. Change the class name to HelloWorld and change the project name to TestVBCode.
5. Generate the TestVBCode. DLL file and run the register component command Regsvr32 path \ TestVBCode. DLL on Windows to register the file. (The uninstall component command is Regsvr32/u path \ TestVBCode. DLL)
6. Create the Test. asp file. The Code is as follows:
<%
'Vb self-built function call format
'Set object name = Server. CreateObject ("project name. Class Name ")
'Object name. self-built function name
Set MyTestObj = Server. CreateObject ("TestVBCode. HelloWorld ")
MyTestObj. SayHello
%>
7. The result of running the Test. asp file is as follows:
Hello World
The above instances will open the door to your vbprogramming world
Come on!