Some beginners who are new to ASP may not be able to fully understand it. The editor of Wuxin Technology Channel has found some methods to write ASP classes. Interested friends can refer to the content introduced by Wuxin Technology Channel to you.
"ASP Design Pattern"
dispbbs.asp?boardID=20&ID=247879
First of all, the ASP class is composed of events and methods (they are members of the class). If you have not yet come into contact with it, you can first take a look at the following instructions:
In the Class block, members are declared as Private (private members, only called inside the class) or Public (public members, only called inside and outside the class) through the corresponding declaration statement. Declared as Private will only be visible within the Class block. Declared as Public is not only visible inside the Class block, but also to code outside the Class block. Not explicitly declared using Private or Public is defaulted to Public. A procedure (Sub or Function) declared as Public inside a class's block will become a method of the class. Public variables will become properties of the class, the same properties explicitly declared using Property Get, Property Let, and Property Set. The default properties and methods of classes are specified with the Default keyword in their declaration section.
Please read the above section patiently, let’s take a look at an example below:
<%
'//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Class myClass
'//----Declare (declare is definition) the inner (private [Private]) variable of the myClass class
Private strAuthor
Private strVersion
Private strExample
'//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'//----Class_Initialize() is the initialization event of the class. As long as you use this class at the beginning, the execution of this part will be triggered. Below we will initialize the author and version of the class in the member and show on the screen that the class has started.
Private Sub Class_Initialize()
strAuthor = "coldstone"
strVersion = "1.0"
Response.Write "
myClass has begun
"
End Sub
'//----Class_Terminate() is the end event of the class. As soon as you exit the class, the event will be triggered. Next, we will set the event in this event that the class has ended on the screen when exiting the class.
Private Sub Class_Terminate()
Response.Write "
myClass is over
"
End Sub
'//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'//----This method returns a copyright information
Public Sub Information()
Response.Write "
Coding By coldstone @时.
"
End Sub
'//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'//------A property of the specified class, which allows the user to initialize the strExapmle variable
Public Property Let setExapmle(ByVal strVar)
strExapmle = strVar
End Property
'//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'//-----Define the attribute of the class, which returns a version number
Public Property Get Version
Version = strVersion
End Property
'//-----Define the attribute of the class, which returns the author number of the class
Public Property Get Author
Author = strAuthor
End Property
'//-----Define the attribute of the class, which returns a version number
Public Property Get Exapmle
Exapmle = strExapmle
End Property
End Class
%><%
'//------ Here is an example of using this class
Dim oneNewClass
Set oneNewClass = New myClass
Response.Write "Author: "& oneNewClass.Author &"
"
Response.Write "version: "& oneNewClass.Version &"
"
oneNewClass.setExapmle = "This is an example of a simple class"
Response.Write "User-defined:" & oneNewClass.Exapmle &"
"
oneNewClass.Information
Set oneNewClass = Nothing
%>
The above article is a detailed explanation of the method of writing ASP classes shared by the editor of the False New Technology Channel. I hope it will be helpful to your understanding!