Organize documents related to Class in ASP

Source: Internet
Author: User
Tags vbscript class

Class Object
The object created using the Class statement. Provides access to various events of the class.

Description

Explicit declaration of a variable as a Class type is not allowed. In the context of VBScript, the term "Class Object" refers to any object defined using the VBScript Class statement.

After using the Class statement to create a Class definition, you can create an instance of the Class in the following form:

Dim X
Set X = New classname
Because VBScript is a later constrained language, the following practices are not allowed:

Dim X as New classname
-Or-

Dim X
X = New classname
-Or-

Set X = New Scripting. FileSystemObject

Class Object events
Class Object provides access to Class events.

Initialize event
This event occurs when a class instance is created.

Private Sub Class_Initialize ()
Statement
End Sub
During class initialization, the statements part consists of zero or more code statements to be run.

Description
The following example demonstrates the usage of the Initialize event.

Class TestClass
Private Sub Class_Initialize 'sets the Initialize event.
MsgBox ("TestClass started ")
End Sub
Private Sub Class_Terminate 'sets the Terminate event.
MsgBox ("TestClass terminated ")
End Sub
End Class

Set X = New TestClass 'to create a TestClass instance.
Set X = Nothing 'delete the instance.

Terminate event

This event occurs when the instance of the associated class is terminated.

Private Sub Class_Terminate ()
Statement
End Sub
During class initialization, the statements part consists of zero or more code statements to be run.

Description
The following example demonstrates how to use the Terminate event.

Class TestClass
Private Sub Class_Initialize 'sets the Initialize event.
MsgBox ("TestClass started ")
End Sub
Private Sub Class_Terminate 'sets the Terminate event.
MsgBox ("TestClass terminated ")
End Sub
End Class
Set X = New TestClass 'to create a TestClass instance.
Set X = Nothing 'delete the instance.

Class statement
Declare the name of a class and define the variables, attributes, and methods that constitute the class.
Class name
Statements
End Class
Parameters
Name is required. Class Name. Follow the standard variable naming rules.
Statements is required. One or more statements define Class variables, attributes, and methods.

Description
In the Class block, the Member is declared as Private or Public 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 visible to code outside the Class block. If Private or Public statements are not used, the default value is Public.
The process (Sub or Function) declared as Public within the block of the class will become the method of the class. Public variables will become attributes of the class, the same as those explicitly declared using Property Get, Property Let, and Property Set. The Default attributes and methods of classes are specified with the Default keyword in their Declaration section. For more information about how to use this keyword, see the topic of a separate statement.

Property Get statement
In the Class block, declare the name, parameters, and code of the subject that constitutes the Property process for obtaining (returning) the Property value.
[Public [Default] | Private] Property Get name [(arglist)]
[Statements]
[[Set] name = expression]
[Exit Property]
[Statements]
[[Set] name = expression]
End Property
Parameters
Public indicates that the Property Get process can be accessed by other processes in all scripts.
Default is only used with the Public keyword, indicating that the Property defined in the Property Get process is the Default Property of the class.
Private indicates that the Property Get process is accessible only for other processes in the Class block that define it.
Name Property Get process name. It complies with standard variable naming rules, except that it can be used with the Property Let or Property Set process in the same Class block.
Arglist the Variable list represents the parameters passed to the Property Get process when it is called. Multiple parameters are separated by commas. The name of each parameter in the Property Get process must be the same as that in the Property Let process (if any ).
Statements
Any group of statements will be executed in the subject of the Property Get process.
Set
Keyword used when the object is used as the return value of the Property Get process.
The Return Value of the expression Property Get process.

Description
If Public or Private statements are not used, the Property Get process is declared Public by default, that is, they are visible to all other processes in the script. The value of local variables in the Property Get process is not saved between different process calls.

The Property Get process cannot be defined within any other process (such as a Function or Property Let.

The Exit Property statement will immediately Exit the Property Get process. The program will continue to execute the program after the statement that calls the Property Get process. The Exit Property statement can appear in any position in the Property Get process, with no limit on the number of times.

Similar to Sub and Property Let processes, the Property Get process can accept parameters, execute a series of statements, and change the value of parameters. However, unlike Sub and Property Let, the Property Get process can be used on the right side of the expression to return the Property value in the same way as using Function or Property name.

Requirements
Version 5

Property Let statement
In the Class block, the Declaration names, parameters, and Code constitute the subject of the Property process for setting the Property value.
[Public | Private] Property Let name (
[Arglist,] value
)
[Statement]
[Exit Property]
[Statement]
End Property
Parameters
Public indicates that the Property Let process can be accessed by all other processes in all scripts.
Private indicates that the Property Let process can only be accessed by other processes in the defined Class block.
Name Property Let process name; follow the standard variable naming rules, the difference is that its name can be the same as the Property Get or Property Set process in the same Class block.
Arglist the Variable list represents the parameters passed to the Property Let process during the call. Multiple parameters are separated by commas. The name of each parameter in the Property Let process must be the same as that in the Property Get process. In addition, there is always one more parameter in the Property Let process than in the corresponding Property Get process. This parameter is the value of the attribute to be assigned.
Value this variable contains the value to be assigned to the attribute. When the process is called, this parameter appears on the right side of the call expression.
Any set of statement statements will be executed within the subject of the Property Let process.

Description
If Public or Private is not explicitly specified, the Property Let process is set to Public by default, that is, they are visible to all other processes in the script. The value of local variables in the Property Let process is not saved between different process calls.

The Property Let process cannot be defined within any other process (such as Function or Property Get.

The Exit Property statement causes immediate Exit from the Property Let process. The program will continue to execute the statement after calling the Property Let process. The Exit Property statement can appear in any position in the Property Let process and has no limit to the number of times.

Note that each Property Let statement must define at least one parameter for the defined process. This parameter (the last parameter when multiple parameters exist) contains the attribute value to be assigned when the Property Let statement is called. This parameter is called value in the previous syntax.
Similar to the Function and Property Get processes, the Property Let process is a separate process. It can accept parameters, execute a series of statements, and change the value of parameters. However, unlike the Function and Property Get processes, both of them return a value, while the Property Let process can only be used on the left side of the attribute value assignment expression.

Requirements
Version 5

Property Set statement
In the Class block, the Declaration name, parameters, and Code constitute the subject of the Property process that sets the reference to the object.
[Public | Private] Property Set name (
[Arglist,] reference
)
[Statement]
[Exit Property]
[Statement]
End Property

Parameters
Public
Indicates that the Property Set process can be accessed by all other processes in all scripts.
Private
It indicates that the Property Set process can only be accessed by other processes in the same declared Class block.
Name
The name of the Property Set process. It complies with the standard variable naming rules, but the name can be the same as the Property Get or Property Let process in the same Class block.
Arglist
Variable list, which indicates the parameter that is passed to the Property Set process when it is called. Multiple parameters are separated by commas. In addition, the Property Set process will always have one more parameter than the corresponding Property Get process. This extra parameter is the object assigned to the attribute.
Reference
Variable, which contains the object reference on the right of the value assigned by the object reference.
Statement
Any group of statements to be executed in the subject of the Property Set process.

Description
Unless explicitly specified using Public or Private, the Property Set process is Set to the default Public mode, that is, all other processes in the script are visible. During different process calls, local variables in the Property Set process are not saved.

The Property Set process cannot be defined in any other process (such as a Function or Property Let.

The Exit Property statement will immediately Exit the Property Set process. The program will continue to execute the statement after calling the Property Set process. The number of Exit Property statements is unrestricted and can appear anywhere in the Property Set process.

Note that each Property Set statement must define at least one parameter for the defined process. When the process defined by the Property Set statement is called, this parameter (the last parameter when multiple parameters are used) will provide the actual object reference for the Property. In the preceding syntax, this parameter is called a reference.
Similar to the Function and Property Get processes, the Property Set process is a separate process. It can have several parameters, execute a series of statements, and change the value of parameters. However, unlike the Function and Property Get processes, both functions and processes can return values, while the Property Set process object references the left side of the value assignment (Set Statement.

Requirements
Version 5

Public Statement
Define public variables and allocate buckets. Define private variables in the Class block.
Public varname [([subscripts])] [, varname [([subscripts])]...
Parameters
Varname
Variable name, which follows the naming rules of standard variables.
Subscripts
The dimension of the array variable. up to 60-dimensional arrays can be declared. The subscripts parameter uses the following syntax:
Upper [, upper]...

The lower bound of the array is always 0.

Description
Public Statement variables can be used in all processes in all scripts.

Before using a variable that references an object, you must use the Set statement to assign an existing object to the variable. Before assigning values, the declared object variable is initialized to Empty.

You can also use a Public statement with empty parentheses to declare a dynamic array. After declaring a dynamic array, you can use the ReDim statement to define the dimension and element of the array. If you try to re-declare the dimension of the array variable, and the size of the array variable has been explicitly specified in the Private, Public, or Dim statement, an error occurs.

The following example illustrates how to use the Public statement:
Public MyNumber 'public Variant variable.
Public MyArray (9) 'Public array variable.
Multiple public declarations of 'variant variables.
Public MyNumber, MyVar, YourNumber

Private statement
Define private variables and allocate buckets. Define private variables in the Class block.
Private varname [([subscripts])] [, varname [([subscripts])]...
Parameters
Varname
The name of the variable. Follow the naming rules of standard variables.
Subscripts
The dimension of the array variable. up to 60-dimensional arrays can be declared. The subscripts parameter uses the following syntax:
Upper [, upper]...

The lower bound of the array is always 0.

Description
Private statement variables can only be used in scripts that declare the variables.

Before using a variable that references an object, you must use the Set statement to assign an existing object to this variable. Before assigning values, the declared object variable is initialized with Empty.

You can also use a Private statement with empty parentheses to declare a dynamic array. After declaring a dynamic array, you can use the ReDim statement to define the dimension and element of the array. If the array size is explicitly specified in the Private, Public, or Dim statement, but an attempt is made to re-declare the array dimension, an error occurs.

Note that when a Private statement is used in the process, the Private statement is usually placed at the beginning of the process.
The following example illustrates how to use a Private statement:
Private MyNumber 'private Variant variable.
Private MyArray (9) 'Private array variable.
Multiple private declarations of the 'variant variable.
Private MyNumber, MyVar, YourNumber

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.