Objects and classes in VB

Source: Internet
Author: User

VB, a non-fully object-oriented programming language, is more generic than other advanced programming languages. Objects are just the instantiation of classes, and classes are a huge set of abstract objects. Class instantiation object, the object is abstracted into a class.



In VB, objects are widely used. Columns such as common forms and various controls are the instantiation results of classes. However, there are several types of objects, such as global objects, referenced objects, and custom objects. They are used in different ways. Let's talk about their usage differences.

1. Common objects: common objects. Let's take an example! Command Control, that is, the command button. It can be used directly in the toolbox, and some code or something can be added in it. The command control is prepared by someone else. We can use it directly.

2. Global Object: A Global object is a unique instance of a class. It can be used directly in VB, just like some common objects. For example, app and error object.

3. reference object: For reference objects and custom objects, the referenced objects must be referenced first, declared, and created before they can be used, and finally abolished, the purpose of revocation is to release it from the memory.

4. user-Defined Object: A User-Defined Object is defined by the class. Its usage must be instantiated from the class, declared, and then created, so that it can be used, the referenced object must be revoked after it is used up.

We have to revoke custom and referenced objects after they are used. What is the purpose of revocation? As I have mentioned above, it is to release them from the memory. Imagine that the memory of a machine is limited. If we cancel them, they will still be in the memory, when we use more, the memory usage is small, and if there are more objects, conflicts may easily occur if we do not release them. In this case, the program will crash unexpectedly.


As mentioned above, the class in VB is an abstract set of some objects, and there are many classes in VB. Here I will only detail the custom classes.

The usage of a custom class is slightly different from that of a class we often use. It also has methods, mappings, events, and so on. For example, all forms are a type-Form class. In a form, we can directly use its attributes, methods, and events, but in a custom class, its Attributes need to be written by ourselves, and the events need to be defined by ourselves.

When defining an attribute, we use the attribute process (property). The attribute process consists of the read attribute process and write attribute process, when writing a property, the write operation on the value attribute and the object attribute is different. The object uses set and the value uses let.

Custom events are different from common functions or processes:

We often define functions in modules or forms. They can directly accept messages sent from forms and then execute them. In a custom event, it requires an intermediate, which is the event source variable and is responsible for receiving messages. In fact, an event is a message, when we use it, we need to first define the event (public event), then generate the event (raiseevent), and send the message to the event source variable, most event source variables are some objects here, and these objects will be sent for execution.

Like Paul Vientiane, Vientiane is the object. Class is the higher meaning of the object, and the object is the final explanation of the class.

Objects and classes in VB

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.