Monday, March 23, 2009

Classes and Object in Visual Basic.NET

We were asked today to do a blog on classes and objects, so after doing some research, I have come up with the following information.

Visual Basic.NET is what is known as an Object Oriented language. This means that the programs designed using this language run based around a series of objects. The amount of objects will depend on the complexity of the program, but they must have at least one object (the "form") in order to run (not that you would do this as there's no point in having just a form pop up. It would serve absolutely no purpose.) No matter whether your program is designed to run in a windows, web or mobile application, it will have to have a form that it uses as a "container" for the rest of the program.

For example, a button is an object. It must be placed on a form before it can be used as part of a program. The button itself will have a click event which is part of the button class. To use an explanation from Free computer Tutorials:
A Class is the code itself; the code becomes an Object when you start using it.
In other words, when you place a button on to the form and double click it, Visual Studio will create a class that can be used for that object. You then take that class and add more code to it to make the button usable. A clear button as an example can have code that will cause it to clear other objects (such as textboxes and labels) in your program. For instance, you may have a textbox on your form which will cause a label to be displayed once the user clicks on the submit button. The clear button can then be made to clear the text from the textbox, clear the text in the label and put the focus back on the textbox ready for more input from the user.

In the instance above, the button class "clear" will do all or any of those things mentioned and in this case, becomes the Clear Button object.

I hope this hasn't been too confusing, and if you understand it, please explain it to me... :-)

No comments:

Post a Comment