1. Open your microsoftvisualbasic:
Click OK. Follow the steps in blue below.
2. Modify the project name and class module name:
Click 3, change 4 to Bi, and then click 5:
Change to cjjer at 6.
3. Add to reference ASP:
Click "Reference" and select "microsoftactiveserverpagesobjectlibrary.
Click 9.
Note:
Server Components
First, the server components should be different from the client components. the client components are transmitted over the network and work with HTML. and can only be used on IE. however, the server component runs on the server, and it performs various operations on the server. therefore, all browsers can enjoy it, relying on servers rather than browsers.
When IIS is requested to execute an ASP Program First, it finds Code And run it (or code between <SCRIPT runat = Server> </SCRIPT> ). if this ASP program was previously called, it will return HTML code to the user using the compiled program in the memory. If not, it will re-compile. here, ASP is a little more speed advantage than CGI, Because CGI uses a thread for every request. in this way, the server resources are greatly consumed.
I don't want the program you write to run on IIS !?! Now you can do it! When using vb5 (of course, it is VB6 now), you can create a dynamic linked libraries (DLL file), which can be run directly on IIS (if there is an ASP file for request ).
System and software requirements
You need a 32-bit operating system to run ASP. Of course, you also need to install IIS or PWS. Our program is developed in the Windows 95 + PWS + vb5 environment.
Let's get started.
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, from which Microsoft Active Server Pages Object Library is selected.
Name projects and Classes
Now let's name project1 and class1 based on our hobbies! Naming them is also very important. We will use this project name and class name to create an instance for this component in the future! The following is a detailed description.
How can I change my name!
Change the project name to exmaple, and the class name is helloword.
How to use projects and Classes
Now we have our own project (example1) and Class Name (helloworld ). in the future, we will use their names in ASP code to reference this component. in ASP, We reference it as follows:
Set objreference = server. Createobject ("projectname. classname ")
References to our project are:
Set objreference = server. Createobject ("example1.helloworld ")
Now we can use objreference to call the function we created in the component. We will write a sayhello subroutine. The code we run is as follows:
<%
Set objreference = server. Createobject ("example1.helloworld ")
Objreference. sayhello
%>
To use ASP in the helloword class, you must write an onstartpage
The sub-function is as follows:
Public sub onstartpage (passedscriptingcontext as scriptingcontext)
Set myscriptingcontext = passedscriptingcontext
End sub
Now, no matter when the user accesses an ASP file with this component, IIS will send scriptingcontext to our object for use. this scriptingcontext includes all ASP methods and attributes. this allows us to access all ASP objects. see the following code:
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
In the future, we can use myapplication in VB to replace the application in ASP. Likewise, we can replace the request, server..., but we want to declare these variables before onstartpage:
Private myscriptingcontext as scriptingcontext
Private myapplication as application
Private myrequest as request
Private myresponse as response
Private myserver as server
Private mysession as session
Use ASP objects
Our variables can now be used like standard ASP objects! For example, we often use request. Form () in ASP to collect the data for submitting forms. Now we implement this function in our VB. The Code is as follows:
Implemented in ASP:
<%
Mytempvariable = request. Form ("username ")
Response. Write ("You entered" & mytempvariable & "as your user name ")
%>
Implemented in VB:
Mytempvariable = myrequest. Form ("username ")
Myresponse. Write ("You entered" & mytempvariable & "as your user name ")
By using myresponse instead of response, we can use all response methods. Of course, the name of myresponse can be obtained at will, and you can even get response.