Analysis of the concepts of attributes, methods and events in VB

Source: Internet
Author: User

All objects in the Visual Basic language have their own properties, methods, and events, including forms and controls. You can treat a property as an attribute of an object, treat a method as an action of an object, and treat an event as a response to an object.

Objects in everyday life, such as helium balloons, also have properties, methods, and events. The properties of a balloon include the visible properties, such as its height, diameter, and color. Other properties describe its state (inflated or deflated) or the invisible attribute (Attribute), such as its useful life. Although the property values for each balloon may vary, all balloons have these properties.

Balloons also have known methods or operations that it can perform. It has an inflatable method (filled with helium), a degassing method (releasing the gas) and an ascending method (to release the balloon). Again, all balloons can execute these methods.

Balloons can also respond to specific external events. For example, a balloon responds to a punctured event with a blow-off or a release event with an ascending response.

properties, methods, and Events

Balloons have attributes (Color, Height, and Diameter) that respond to events (puncture) and can execute methods (Deflate and Makenoise).

Property

If you want to design a balloon program, its Visual Basic code might resemble the following "code" that sets the balloon property.

Balloon.color = Red

Balloon.diameter = 10

balloon.inflated = True

Note that the order of the Code-the object (Balloon) is followed by the attribute (Color), and then the assignment (= Red). You can change the color of balloons by replacing them with different values.

Method

The balloon method is called as follows.

Balloon.inflate

Balloon.deflate

Balloon.rise (5)

This order is similar to the order of the attributes, that is, the object (noun) followed by the method (predicate). In the third method there is another item called "parameter", which specifies the distance the balloon will rise. Some methods have one or more parameters that further describe the action to be performed.

Event

The balloon may respond to the event as shown below.

 
Sub Balloon_puncture ()    balloon.makenoise ("Bang")    balloon.deflate    balloon.inflated = FalseEnd Sub

In this case, the code describes the behavior of the balloon when the puncture event occurs. When this event occurs, the Makenoise method is called using the "Bang" (type of noise emitted) parameter, and then the Deflate method is called. The inflated property is set to False because the balloon is no longer inflated.

Although you can't actually write a program for a balloon, you can write a Visual Basic form or control. As a programmer, you have a responsibility. You can decide which properties should be changed, which methods should be called, or which events should be responded to to achieve the desired appearance and behavior.

Analysis of the concepts of attributes, methods and events 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.