ASP class (VBScript Class) Basics Learning

Source: Internet
Author: User
Tags vbscript class

First, the ASP (VBScript) class is made up of events and methods, which are members of the constituent class.

In a class block, a member is declared private (private, only within a class) or public (publicly owned, which can be called outside of a class) by the appropriate declaration statement. The declared Private will be visible only within the Class block. Being declared public is not only visible inside the class block, but also for code outside of the class block. Default is public that is not explicitly declared using Private or public. A procedure (Sub or Function) declared as public within a block of a class becomes a method of the class. The public variable becomes the property of the class, the same as the properties that are explicitly declared by using the property's get, the attribute let, and the Set. The default properties and methods of a class are specified in their declaration section by the default keyword.

Now let's take a look at an example

<script Language=vbscript runat=server>
Class MyClass
'//----declaration (Declaration is defined) the internal (private [private]) variable of the class MyClass class
Private Strauthor
Private strversion
Private Strexample
'//---------------------------Define event-------------------------------for class//
'//----Class_Initialize () is the initialization event for the class, which first triggers the execution of that part, and then we initialize the author and version of the class in that member and the screen shows that the class has begun.
Private Sub Class_Initialize ()
Strauthor = "Si source"
Strversion = "1.0"
Response.Write "<br>myclass started <br>"
End Sub
'//----class_terminate () is the end event of the class, and as soon as the class is exited, the event is triggered, and we will set the event to exit the class when the class is displayed on the screen.
Private Sub Class_Terminate ()
Response.Write "<br>myclass over <br>"
End Sub
'//---------------------------user-defined methods-------------------------------//
'//----The method returns a version information
Public Sub information ()
Response.Write "<br>coding by <a href= ' mailtcoder@sinobe.com ' >Maxid_Zen</a> @
<a href= ' http://www.design60s.com ' >www.design60s.com</a>.<br> '
End Sub
'//---------------------------define the output properties of the class-------------------------------//
'//----The property of a class that allows the user to initialize the STREXAPMLE variable
Public Property Let Setexapmle (ByVal Strvar)
Strexapmle = Strvar
End Property
'//---------------------------define the output properties of the class-------------------------------//
'//----Define the properties of the class, which is to return a version number

Public Property Get Version
Version = Strversion
End Property
'//----Define the property of the class, which is the author number that returns the class
Public Property Get Author
Author = Strauthor
End Property
'//----Define the properties of the class, which is to return 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 = New 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
%>

Related Article

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.