ASP Call DLL and ASP package DLL instances

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.