We've mentioned OOP before, but what is OOP? This course hasn't looked at that question closely yet. Since it's such an important topic, this segment of the tutorial will introduce it and we'll cover it again in a later segment and at greater depth.
Today, OOP is thoroughly integrated into programming. But for the first several decades of programming, we used a model that people call "spaghetti code" today. That model earned the name because the sequence of statements that a program would execute was as hard to follow and understand as a mass of spaghetti. Big, "spaghetti pot" programs did their work with complicated branching (Go To statements (something we don't even use now in Visual Basic), conditions (If ... Then ... Else) and looping (For ... Next).
To solve this problem, computer scientists, starting with Edsger W. Dijkstra, invented a new model where the work gets done by software "objects".
In part 3 of this tutorial, we developed a version of Hello World that could display the message in three languages. We also looked at an example of analysis and design for the program. In this analysis and design, we saw that our "translating" Hello World accepted one input - the language to use to display the message - and created one output - the display. That's the essence of a software "object". A very simple definition of an object is a program that has methods (things that it will do) and properties (information held in the object) that you can use in another program. A programmer can make as many copies (instances) of an object as are needed. Making a copy of an object in the program memory is called instantiation.
All software can be made completely from objects. A demonstration of that is that .NET is completely made from objects.
VB.NET Controls
The control is one of the most important objects in VB.NET. Consider this simplified statement. Controls are simply objects supplied by Microsoft (you can also code them yourself or get them from third party suppliers) that you can add to your project using something called the Toolbox. Keep in mind that the Toolbox is just a convenience that Visual Studio and VB.NET Express both use to organize controls and make them easier to use.
(You will also run into the term, "component" a lot and many people use it interchangeably with "control". In general, a control has a visual interface - like a Button - but a component does not - like a Timer. There are actually two classes in VB.NET named Component and Control that can be used to define the difference very technically, but usually it's not necessary to be that precise.)
As described in the first lesson, VB.NET will create the "event code" for the control. I've added a MsgBox statement to the code automatically created.
Private Sub Button1_Click( _
ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
MsgBox(Today.DayOfYear.ToString)
End Sub
The key items are:
Objects: sender, e, Button1 and Today
A Property: DayOfYear
A Method: ToString
An Event: Click
Let's consider these one at a time.
First, the objects. In .NET, it's popular to say, "everything is an object" and that's pretty much true. You can think of properties, methods and events as being what objects are made of. Objects can come from a number of places but there's one tool that you can use to find any of them in VB.NET called the Object Browser. You'll find it in the toolbar at the top of the window in VB.NET.
The "Properties Window" is a place where you can find the available properties for an control and where you can set their initial values. (That's one thing that sets controls apart from other objects.) But if you want to change them in program code, Visual Studio Intellisense shows you a list that includes both Properties and Methods that can be used with any control.
And finally, in part 1 of this series, we were introduced to the concept of an event. When the Click event is "raised" this subroutine is executed. The available events for a control can all be seen in the Declarations dropdown listbox in VB.NET as shown in the illustration below.
--------
Click Here to display the illustration
Click the Back button on your browser to return
--------
On the next page, we take a more theoretical view of objects and OOP - Object Oriented Programming.

