For ASP users, the operation of the database is actually very simple. They also need a lot of time to consider code logic and application. The above is a detailed explanation of ASP class writing. How much do you know?
First of all, the ASP classes are composed of events and methods (they are members of the class). If you have not been exposed to them, you can first look at the instructions below (haha, I am learning and selling now, please forgive me if I don’t say it well)
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 blue part in your heart, let’s take a look at an example below
<script language=vbscript runat=server>
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 = Siyuan
strVersion = 1.0
Response.Write <br>myClass is beginning<br>
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 <br>myClass is over<br>
End Sub
'//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'//----This method returns a version information
Public Sub Information()
Response.Write <br>Coding By <a href='mailto:[email protected]'>Maxid_Zen</a> @ <a href='http://www.design60s.com'>www.design60s.com</a>.<br>
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
</script>
<%
'//------ Here is an example of using this class
Dim oneNewClass
Set oneNewClass = myClass
Response.Write Author: & oneNewClass.Author & <br>
Response.Write Version: & oneNewClass.Version & <br>
oneNewClass.setExapmle = This is an example of a simple class
Response.Write User-defined: & oneNewClass.Exapmle & <br>
oneNewClass.Information
Set oneNewClass = Nothing
%>
The above article is a detailed explanation about the writing of ASP classes. I believe everyone has understood it clearly! If you want to learn more technical knowledge, please continue to pay attention to the wrong new technology channel!