ASP can be like.. net. below I will write a simple and practical question about ASP encapsulation for you to get started easily. Of course, the most important thing to prepare on the homepage is that I used VB6.0 as a VB tool.
Start your VB and select the ActiveX icon. This icon can be found in the new project! VB provides a default project name (project1) and Class Name (class1 ). we will change both names. before renaming, make sure that we have the Microsoft Active Server Pages Object Library, which is useful in our programs. select "project" from the menu, and then select "Reference". The "Reference" window appears.
Select Microsoft Active Server Pages Object Library.
First, create a class file in VB: Project name: EXP
Code:
Dim myapplication as application
Dim myrequest as request
Dim myresponse as response
Dim myserver as server
Dim 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 sub hellow ()
Myresponse. Write ("Hello World ")
End sub
Public sub Google ()
Myresponse. Write ("ssssssssssss ")
End sub
NOTE: For the objects transmitted by scriptingcontext to us, please use. This scriptingcontext includes all ASP methods and attributes. This enables us to access all ASP objects.
Of course, another step here is to generate the exp. dll file. After the file is generated, you can use regsvr32 D:/Vb-Asp/exp. DLL to register it)
ASP page:
<% @ Language = VBScript %>
<HTML>
<Head>
<Title> Example 1 </title>
</Head> <body>
<%
Dim OBJ
Set OBJ = server. Createobject ("exp. aspdll ")
OBJ. hellow
Response. Write ("<br> ")
OBJ. Google
%>
</Body>
</Html>
Note:
Set OBJ = server. Createobject ("exp. aspdll") Where exp is the project name and aspdll is the class name. Set OBJ = server. Createobject ("project name. Class Name ")
Test passed.
========================================================== ==============================
For more complex applications, you can use this instance to scale out.
For example:
Public sub connstr2 ()
Set conn = myserver. Createobject ("ADODB. Connection ")
Conn. Open "driver = {Microsoft Access Driver (*. mdb)}; DBQ =" & myserver. mappath ("codata. mdb ")
Set rs = conn. Execute ("select * From News ")
Do while not Rs. EOF
Myresponse. Write (RS ("news_title") & "<br> ")
Rs. movenext
Loop
Rs. Close
Set conn = nothing
End sub
This is encapsulated by the database connection code. Of course, we need to add the ADO reference here.