Collation data of class-related content in ASP _asp class

Source: Internet
Author: User
Tags arrays class definition naming convention vbscript class
Class Object
The object created using the Class statement. Provides access to a variety of events for a class.

Description

Explicitly declaring a variable as Class type is not allowed. In the context of VBScript, the term "class object" refers to any object defined with the VBScript class statement.

After you have established a class definition using the class statement, you can create an instance of the class in the following form:

Dim X
Set X = New classname
Since VBScript is a late-bound language, the following practices are not allowed:

Dim X as New classname
Or

Dim X
X = New ClassName
Or

Set X = New Scripting.FileSystemObject

Event for Class Object
Class object provides access to the events of the class.

Initialize Events
This event occurs when an instance of a class is created.

Private Sub Class_Initialize ()
Statement
End Sub
When the class is initialized, the statements part consists of 0 or more code statements that will be run.

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

Class TestClass
Private Sub class_initialize ' sets Initialize event.
MsgBox ("TestClass started")
End Sub
Private Sub class_terminate ' sets Terminate event.
MsgBox ("TestClass terminated")
End Sub
End Class

Set X = New TestClass ' Creates a TestClass instance.
Set X = Nothing ' deletes an instance.

Terminate Events

This event occurs when an instance of the associated class terminates.

Private Sub Class_Terminate ()
Statement
End Sub
When the class is initialized, the statements part consists of 0 or more code statements that will be run.

Description
The following example demonstrates the use of the Terminate event.

Class TestClass
Private Sub class_initialize ' sets Initialize event.
MsgBox ("TestClass started")
End Sub
Private Sub class_terminate ' sets Terminate event.
MsgBox ("TestClass terminated")
End Sub
End Class
Set X = New TestClass ' Creates a TestClass instance.
Set X = Nothing ' deletes an instance.

Class statement
Declares the name of a class and the definition of the variables, properties, and methods that make up the class.
Class Name
Statements
End Class
Parameters
The name required option. Class name, followed by the standard variable naming rules.
Statements required option. One or more statements that define the variables, properties, and methods of Class.

Description
In a Class block, a member is declared Private or public through a corresponding 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. For information on how to use this keyword, refer to the individual declaration statement topic.

Property Get Statement
In the Class block, declare the name, parameters, and code of the body that constitutes the property procedure used to get (return) the attribute 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 procedure can be accessed by other procedures in all scripts.
Default is only used with the public keyword, indicating that the attribute defined in the Property Get procedure is a lack of a class.
Private indicates that the property Get procedure is accessible only to other procedures in the Class block in which it is defined.
Names of the Name Property Get procedure, the standard variable naming rule, except that it can be in the same class block with the property let or property Set procedure.
ArgList the variable list represents the arguments passed to it when the Property Get procedure is invoked. Multiple parameters are separated by commas. The name of each parameter in the Property Get procedure must be the same as the corresponding parameter in the Property Let procedure, if any.
Statements
Any set of statements that will be executed in the body of the Property Get procedure.
Set
The keyword to use when the object is returned as a property Get procedure.
Expression The return value of the Property Get procedure.

Description
If you are not explicitly declared with public or Private, the Property Get procedure is default to common, that is, they are visible to all other procedures in the script. The value of a local variable in a Property Get procedure is not saved between different procedure calls.

The Property Get procedure cannot be defined inside any other procedure, such as a Function or Property let.

The Exit Property statement causes an immediate exit from the Property Get procedure. The program will continue to execute after the statement that calls the Property Get procedure. The Exit Property statement can appear anywhere in the property Get procedure, not limited to the number of times.

Like a sub and a Property Let procedure, a Property Get procedure is a process that accepts parameters, executes a series of statements, and changes the value of a parameter. However, unlike sub and property lets, a Property Get procedure can be used on the right side of an expression, returning the value of the attribute in the same way as using a function or attribute name.

Requirements
Version 5

Property Let statement
In Class blocks, declaring names, parameters, and code, and so on, constitute the body of the property procedure that sets the attribute value.
[Public | Private] Property Let name (
[ArgList,] Value
)
[Statement]
[Exit Property]
[Statement]
End Property
Parameters
Public indicates that the property Let procedure can be accessed by all other procedures in all scripts.
Private indicates that the property Let procedure can only be accessed by other procedures within the Class block that is defined.
Name of the Let procedure for the Name property, and a standard variable naming convention that differs only in that its name can be the same as a property Get or property Set procedure in the same Class block.
ArgList the variable list represents the arguments that are passed to the Property Let procedure at the time of the call. Multiple parameters are separated by commas. The name of each parameter of the Property Let procedure must be the same as the corresponding parameter in the Property Get procedure. In addition, the property let process has more arguments than the corresponding Property Get procedure. The parameter is the value assigned to the property.
Value The variable contains the value to assign to the property. When a procedure is invoked, the argument appears to the right of the invocation expression.
Statement any set of statements that will be executed within the body of the property let process.

Description
If you do not explicitly use public or Private to specify, the property Let procedure is set to common by default, that is, they are visible to all other processes within the script. The values of local variables in the property Let process are not saved between different procedure invocations.

The Property Let procedure cannot be defined within any other process, such as a Function or property get.

The Exit Property statement causes an immediate exit from the Property Let procedure. The program will continue to execute from the point following the statement that called the Property Let procedure. The Exit Property statement can appear anywhere in the property let process, not limited to the number of times.

Note that each Property Let statement must define at least one parameter for the defined procedure. The parameter (the last argument when multiple arguments exist) contains the value to assign to the property when it is invoked. This parameter is called value in the preceding syntax.
Like the Function and Property Get procedures, the Property Let procedure is a separate process that accepts parameters, executes a series of statements, and changes the value of the parameter. However, unlike the function and property get procedures, they both return a value, and the property Let procedure can only be used to the left of the attribute assignment expression.

Requirements
Version 5

Property Set Statement
In the Class block, declare the name, parameters, and code, which constitute the body of the property procedure 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 procedure can be accessed by all other procedures in all scripts.
Private
Indicates that the property Set procedure can only be accessed by other procedures in the same Class block that is declared.
Name
The name of the property Set procedure, followed by a standard variable naming convention, but the name can be the same as a property get or Property Let procedure in the same Class block.
ArgList
A list of variables that represents the arguments passed to it when the property Set procedure is invoked. Multiple parameters are separated by commas. Additionally, the property set procedure will always have one more argument than its corresponding property-get procedure. This extra argument is the object to which the attribute is assigned.
Reference
Variable that contains the object reference to the right of the object reference assignment.
Statement
Any set of statements that will be executed in the body of the property Set procedure.

Description
Unless explicitly specified with public or Private, the property Set procedure is set to the default common mode, where all other procedures in the script are visible. When different procedure calls, local variables in the property Set procedure are not saved.

The property Set procedure cannot be defined in any other procedure, such as a function or Property let.

The Exit Property statement causes an immediate exit from the property Set procedure. The program continues to execute the statement after the property Set procedure is invoked. The number of the Exit Property statement is unrestricted and can appear anywhere in the property Set procedure.

Note Each property Set statement must define at least one parameter for the defined procedure. When a procedure defined by a property Set statement is invoked, the argument (the last argument at multiple arguments) provides the actual object reference for the attribute. In the previous syntax, this argument is referred to as a reference.
Like the Function and Property Get procedures, the property Set procedure is a separate process that can have several parameters, execute a series of statements, and change the value of the parameter. However, unlike function and Property get procedures, both functions and procedures can return a value, and the property Set procedure object references the left side of the assignment (Set statement).

Requirements
Version 5

Public statement
Define public variables and allocate storage space. Define a private variable in the Class block.
Public varname[([subscripts])] [, varname[([subscripts])]] ...
Parameters
VarName
The name of the variable, followed by the standard variable naming convention.
subscripts
The number of dimensions of the array variable; You can declare up to 60-d arrays. The subscripts parameter uses the following syntax:
Upper [, Upper] ...

The lower bound of an array is always 0.

Description
The public statement variable can be used for all procedures in all scripts.

Before you can use a variable that references an object, you must assign an existing object to the variable with the Set statement. The declared object variable is initialized to Empty before assigning the value.

You can also declare a dynamic array by using the public statement with empty parentheses. After declaring a dynamic array, you can use the REDIM statement within the procedure to define the dimensions and elements of the array. An error occurs if you attempt to declare the dimension of an array variable, and the size of this array variable has been explicitly specified in Private, public, or DIM statements.

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

Private statement
Define private variables and allocate storage space. Define a private variable in the class block.
Private varname[([subscripts])] [, varname[([subscripts])] ...
Parameters
VarName
The name of the variable, followed by the standard variable naming convention.
subscripts
The number of dimensions of an array variable that can declare up to 60-d arrays. The subscripts parameter uses the following syntax:
Upper [, Upper] ...

The lower bound of an array is always 0.

Description
A Private statement variable can only be used in a script that declares the variable.

Before you use a variable that references an object, you must assign an existing object to the variable with the Set statement. The declared object variable is initialized empty before the assignment.

You can also declare a dynamic array with a Private statement with empty parentheses. After declaring a dynamic array, you can define the dimensions and elements of the array using the REDIM statement within the procedure. An error occurs if the array size is explicitly specified in Private, public, or DIM statements, but an attempt is made to declare the array dimension again.

Note When you use a private statement in a procedure, you usually place the private statement at the beginning of the procedure.
The following examples illustrate how to use Private statements:
Private MyNumber ' proprietary variant variable.
Private MyArray (9) ' proprietary array variable.
' Multiple private declarations for variant variables.
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.