Set usage in VB

Source: Internet
Author: User

Set statement
Assign an object reference to a variable or attribute.
Syntax
Set objectvar = {[new] objectexpression | nothing}
The syntax of the Set statement includes the following parts:
Partial description
Required by objectvar. The name of a variable or attribute, which follows the naming conventions of standard variables.
Optional. New is usually used in Declaration to create objects implicitly. If new and set are used together, a new instance of the class will be created. If objectvar contains an object reference, the reference is released when the new value is added. You cannot use the new keyword to create a new instance of any internal data type or create a subordinate object.

Objectexpression is required. An expression consisting of an object name, other declared variables of the same object type, or functions or methods of the same object type.
Optional. Disassociate objectvar from any specified object. If no other variable points to the object originally referenced by objectvar, assigning it to nothing will release all system and memory resources associated with the object.

Description
To ensure the validity, objectvar must be of the same object type as the assigned object.
Dim, private, public, redim, and static statements only declare variables of referenced objects. Before assigning a variable to a specific object using the set statement, the variable does not reference any actual object.

The following example shows how to use dim to declare an array of the form1 type. Form1 does not actually have an instance. Then, use set to assign the reference of the newly created form1 instance to the mychildforms variable. You can use this code in an MDI Application to create a child form.

Dim mychildforms (1 to 4) as form1
Set mychildforms (1) = new form1
Set mychildforms (2) = new form1
Set mychildforms (3) = new form1
Set mychildforms (4) = new form1
Generally, when you use set to assign an object reference to a variable, You do not create a copy of the object for the variable, but create a reference for the object. Multiple object variables can reference the same object. Because these variables are only references of the object, rather than copies of the object, any changes to the object will reflect all variables that reference the object. However, if the new keyword is used in the Set statement, an instance of the object will be created.

Note: The above conversion from http://hi.baidu.com/zhw0626/blog/item/44e5f189c58e67b00e24446f.html

++ ++ ++

[About get, set, and let]

Get is the property value.
Set is to assign values to object attributes.
Let transmits a variable
There are two methods for a class to expose an attribute (variable) to the outside:
1. You can directly declare this variable with public, so that the external process can easily read and write this variable;
2. Declare the variable with private, and then use property get .../

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.