Visual Basic: Events & Objects

advertisement
Visual Basic: Events & Objects
1.
What are the 5 steps to implement a programming solution to a problem (using Visual Basic)?
Create the interface – place controls on a form,
Set the properties – set the initial characteristics of the controls,
Write the code – write code to react to events,
Save the project – store the project on disk,
Try out the application – test to see how well it works.
2.
Visual Basic applications are event driven. What does this mean?
Event driven programming is programming in response to particular events, such as a key press or a mouse
click (these actions are referred to as events).
3.
What is an event procedure?
When an event occurs Visual Basic runs the code – an event procedure – you have written for it. It is a series
of predetermined actions defined by the programmer that runs when a particular event occurs.
4.
Give some examples of events.
Click, KeyPress, MouseDown, MouseUp, Change, etc.
5.
What is an advantage of event driven programming over traditional?
When an event occurs it is in an unpredictable sequence depending on the decisions made by the user. In
such an environment the screen is being constantly monitored, waiting for the user to do something.
6. Examine this code:
Private Sub cmdDisplay_Click()
txtGreeting.Text = “Hello there!”
End Sub
Identify the names of controls, the property and the event.
Controls – text box, command button
Property – Text “Hello there!”
Event - Click
7.
What is the syntax for naming an event procedure?
Objectname_eventname eg cmdClear_Click ()
8.
What is the syntax for naming a property?
Object.property eg txtGreeting.Text
9.
Event procedures can be used to change the properties of objects. What else might an event procedure do?
Make comparisons between numbers, calculate sums, change text in a text box, label, etc
10. (a) What are the three essential elements of object oriented programming?
Encapsulation -the properties of an object and the processes performed by an object are all encapsulated
within the object itself. Eg what a command button is and what it can do are all contained in a definition of a
command button
Polymorphism – several objects may be able to perform the same action.
Inheritance – one object can be based upon the definition of another. When this happens the new object
inherits the properties and methods of the parent object.
(b) What aspect of OOP is missing from Visual Basic?
Visual Basic does not support the feature of inheritance– It is not an entirely object orientated program, but it
is object based.
Download