Let's take a look at the application object.
Previously, application objects were often used for the connection string between counters and databases.
Take the counter as an example:
Check the global. Asa file first. This is relatively simple.
<Script language = VBScript runat = Server>
Sub application_onstart
Application ("counter") = 0
End sub
</SCRIPT>
Then
Open VB6 and create an ActiveX dll project. Change project name to fcom and class name to fz2
Reference the "Microsoft Active Server Pages object" Object Library.
Create two component events: onstartpage and onendpage
Create a reference of the scriptingcontent class in the event onstartpage.
Instantiation class scriptingcontent.
The Code is as follows:
Option explicit
'Object Declaration
Dim myresponse as response
Dim myrequest as request
Dim myapplication as application
Dim myserver as server
Dim mysession as session
'This event is triggered when the component is created.
Public sub onstartpage (myscriptingcontent as scriptingcontext)
'Instantiate the object
Set myresponse = myscriptingcontent. Response
Set myrequest = myscriptingcontent. Request
Set myserver = myscriptingcontent. Server
Set myapplication = myscriptingcontent. Application
Set mysession = myscriptingcontent. Session
End sub
'This event is triggered when the component is destroyed.
Public sub onendpage ()
'Destroy object
Set myresponse = nothing
Set myrequest = nothing
Set myserver = nothing
Set myapplication = nothing
Set mysession = nothing
End sub
'You can see that the original ASP was moved to VB, and the writing method is the same.
Public sub showcounter ()
Dim intcounter as long
Myapplication. Lock
Intcounter = myapplication ("counter ")
Intcounter = intcounter + 1
Myapplication ("counter") = intcounter
Myapplication. Unlock
Myresponse. Write CSTR (intcounter)
End sub
Test
Open visual interdev6.0 and generate an ASP file
<% @ Language = VBScript %>
<HTML>
<Body>
<%
Dim OBJ
Set OBJ = server. Createobject ("fcom. fz2 ")
OBJ. showcounter ()
%>
</Body>
</Html>
After configuring the virtual directory, you need to put the global. Asa file in the root directory, execute this ASP file in IE, refresh the page, and you will see a constantly changing number.
The usage of application is described here.