ASP class member variables, member functions, and constructor destructors

Source: Internet
Author: User
Tags object constructor end functions variables variable


Class Cfoo
Dim Publicparam ' Declare public member variables with Dim
Private Privateparam ' privacy member variable
' Publicparam = ' public ' cannot be assigned to a member variable within a class tag, outside of a class function
' Const Max_len = 5 ' cannot use const outside of class tags, classes functions

' This function is a constructor that automatically executes when an object is created using set new
Private Sub Class_Initialize ()
Publicparam = "Public" can assign a value to a member variable here
Privateparam = "Private"
End Sub

' This function is a destructor that automatically executes when the object is disposed with set nothing
Private Sub Class_Terminate ()
Response. Write "Release Object"
End Sub

' Public member function (procedure)
' member function (procedure) not required or declared
Sub PrintParam (Index)
If index = 1 Then
Call Printpublicparam ()
ElseIf index = 2 Then
Call Printprivateparam ()
End If
End Sub

' Private member function (procedure)
' Just one more private than the public member function (process)
Private Sub Printpublicparam ()
Response. Write Publicparam
End Sub

Private Sub Printprivateparam ()
Response. Write Privateparam
End Sub
End Class

Dim obj
Set obj = new Cfoo ' Automatically calls the Class_Initialize function, assigning values for Publicparam, Privateparam
Obj.publicparam = "New Public"
Obj.privateparam = "New Private" will have an error because Privateparam is a private variable
Call obj. PrintParam (1) ' shows the value of the Publicparam
Call obj. Printpublicparam () ' will cause an error because printpublicparam is a private function
Set obj = Nothing ' automatically calls the Class_Terminate function, displaying ' release object '



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.