Differences between events and methods in VB

Source: Internet
Author: User

You can regard the human body as a form object and the ear as a control on the form. For example, when you hear a sentence, the onlister event of the ear is activated, private sub ear _ onlister (byval speaker as Speaker) Select case speaker case wife: Call obedient wholeheartedly () Case BOSS: Call obedient () case enemy: me. the hitting (speaker) 'calls the "Human Body" form object's "hitting" method end selectend sub. From the above example, we can see that: 1. Events are activated by external conditions, the method is passive, but the method is active. Therefore, when writing a VB program, we do not need to worry about how the event is activated by the VB event manager. We only need to care about the conditions under which the event is activated; the method should be proactively written into the code and called somewhere, such as "me. human (speaker) ", if you do not take the initiative to call, it will not happen. 2. Write the code in the event. The method is defined by the system. If no code is written in the event, the event will be the same as it did not happen; the method, the system defines the code internally, and does not need to be modified by itself, but may pass the parameter, change the effect of method execution, such as "me. speaker ", if you don't pass a parameter, you don't know who to hit. This is basically the case above .....
 
 
 
The reference document of msdn is described as follows:
Overview of properties, methods, and events Visual Basic Forms and controls are objects with their own properties, methods, and events.
We can regard attributes as the nature of an object, methods as the action of an object, and events as the response of an object.
Objects in daily life, such as balloons played by children, also have attributes, methods, and events.
The attributes of a balloon include some properties that you can see, such as its diameter and color. Other attributes describe the status of the balloon (inflatable or not inflated) or invisible properties, such as its life. By definition, all balloons have these attributes, which may vary depending on the balloon.
Balloons also have inherent methods and actions. For example, the inflation method (with the action of filling the balloon with helium), the venting method (discharge the gas in the balloon), and the rising method (let the balloon fly away ). All balloons have these capabilities.
Balloons also have predefined responses to certain external events. For example, the balloon responds to the incident that stabbed it, and the response to the let-Go event is to take off.
If you can program a balloon, the Visual Basic code is as follows.
The function is to set the attributes of the balloon:
Balloon.Color = Red 
Balloon.Diameter = 10 
Balloon.Inflated = True 
Pay attention to the code syntax, first the object (balloon), then the attribute (color), and then the value assignment (red ). Repeat this statement, but you can change the color of the balloon with a different value.
You can also set properties in the Properties window during the programming stage.
The method for calling the balloon is as follows: balloon. inflate balloon. Deflate balloon. Rise 5
Its syntax is similar to the attribute syntax, and the object (a noun) is followed by the method (a verb ).
In the third example, an additional item, called a parameter, indicates the height of the balloon. Some methods have one or more parameters that further describe the executed action.
The balloon responds to an event as follows:
 Sub Balloon_Puncture() 
Balloon.Deflate 
Balloon.MakeNoise "Bang" 
Balloon.Inflated = False 
Balloon.Diameter = 1 
End Sub 
The code in this example describes the behavior of a balloon when a piercing event occurs: Call the deflate method and call the makenoise method with the "bang" parameter. Because the balloon is no longer in the inflation status, set the inflated attribute to false and set a new value for the diameter attribute.
In fact, balloons cannot be programmed, but visual basic forms or controls can be programmed. As a programmer, you are the owner. You decide which attributes should be changed, which methods should be called, and which events should be responded to obtain the desired appearance and behavior.
 
 
You can regard the human body as a form object and the ear as a control on the form. For example, when you hear a sentence, the onlister event of the ear is activated, private sub ear _ onlister (byval speaker as Speaker) Select case speaker case wife: Call obedient wholeheartedly () Case BOSS: Call obedient () case enemy: me. the hitting (speaker) 'calls the "Human Body" form object's "hitting" method end selectend sub. From the above example, we can see that: 1. Events are activated by external conditions, the method is passive, but the method is active. Therefore, when writing a VB program, we do not need to worry about how the event is activated by the VB event manager. We only need to care about the conditions under which the event is activated; the method should be proactively written into the code and called somewhere, such as "me. human (speaker) ", if you do not take the initiative to call, it will not happen. 2. Write the code in the event. The method is defined by the system. If no code is written in the event, the event will be the same as it did not happen; the method, the system defines the code internally, and does not need to be modified by itself, but may pass the parameter, change the effect of method execution, such as "me. speaker ", if you don't pass a parameter, you don't know who to hit. This is basically the case above .....
 
 
 
The reference document of msdn is described as follows:
Overview of properties, methods, and events Visual Basic Forms and controls are objects with their own properties, methods, and events.
We can regard attributes as the nature of an object, methods as the action of an object, and events as the response of an object.
Objects in daily life, such as balloons played by children, also have attributes, methods, and events.
The attributes of a balloon include some properties that you can see, such as its diameter and color. Other attributes describe the status of the balloon (inflatable or not inflated) or invisible properties, such as its life. By definition, all balloons have these attributes, which may vary depending on the balloon.
Balloons also have inherent methods and actions. For example, the inflation method (with the action of filling the balloon with helium), the venting method (discharge the gas in the balloon), and the rising method (let the balloon fly away ). All balloons have these capabilities.
Balloons also have predefined responses to certain external events. For example, the balloon responds to the incident that stabbed it, and the response to the let-Go event is to take off.
If you can program a balloon, the Visual Basic code is as follows.
The function is to set the attributes of the balloon:
Balloon.Color = Red 
Balloon.Diameter = 10 
Balloon.Inflated = True 
Pay attention to the code syntax, first the object (balloon), then the attribute (color), and then the value assignment (red ). Repeat this statement, but you can change the color of the balloon with a different value.
You can also set properties in the Properties window during the programming stage.
The method for calling the balloon is as follows: balloon. inflate balloon. Deflate balloon. Rise 5
Its syntax is similar to the attribute syntax, and the object (a noun) is followed by the method (a verb ).
In the third example, an additional item, called a parameter, indicates the height of the balloon. Some methods have one or more parameters that further describe the executed action.
The balloon responds to an event as follows:
 Sub Balloon_Puncture() 
Balloon.Deflate 
Balloon.MakeNoise "Bang" 
Balloon.Inflated = False 
Balloon.Diameter = 1 
End Sub 
The code in this example describes the behavior of a balloon when a piercing event occurs: Call the deflate method and call the makenoise method with the "bang" parameter. Because the balloon is no longer in the inflation status, set the inflated attribute to false and set a new value for the diameter attribute.
In fact, balloons cannot be programmed, but visual basic forms or controls can be programmed. As a programmer, you are the owner. You decide which attributes should be changed, which methods should be called, and which events should be responded to obtain the desired appearance and behavior.
 
 

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.