Learn the most popular programming language of the most popular Operating System: Windows

Ad

Understanding Objects as Instances of Classes

In the last example the two text boxes and the form we have tried are referred to as windows as well as objects.  In a Windows program, just about everything that you see on the screen is a window, and many items that you don’t see are windows.

In a standard Windows word processing program, such as Word or WordPerfect, every button on the toolbars is a separate window.  Every open document is a separate window, as are the dialog boxes that permit you to select different font properties, and the rulers that allow you to set tabs and adjust page width.  These windows are objects, which have their own properties, methods, and events.  The Windows operating system sends messages to the windows to respond to user events.

Object Classes

How many different kinds of windows can there be? As many as a programmer can imagine and create!  The design of the windows operating system provides several standard window types called classes.  There can be many classes of objects in addition to the standard types.  Whether you know it or not, you probably are already familiar with several standard Windows classes and their behaviors, including the following:

  • Button
  • ComboBox
  • Edit
  • ListBox
  • Scrollbar

As you might suspect by now, some of the controls in the Visual Basic toolbox are related to these standard Windows classes.  For example, a Text Box control is closely related to the base Windows Edit class.

A class is like a cookie cutter: It defines how an object should look and behave when it is first created.  to work with Visual Basic objects, you first use this cookie cutter to cut out the uniform shape of your object.  After you have this basic shape (called an instance of the class), you can manipulate the object by altering its properties or by calling one of the object’s methods to make the object behave in a certain way.

Often Visual Basic creates an instance of a class for you.  When you add a Text Box control to a form, Visual Basic creates an instance of the visual Basic Text Box control class.  After it is created, you can manipulate it.  To alter text displayed in a text box objects named txtDisplay, for instance, you would execute the following instruction:

txtDisplay.Text = "Welcome to Visual Basic"

In other circumstances, you will be required to create an instance of the class (an object) yourself.  You will even define your own classes and then create multiple instances (objects) from the class you have defined.

Technorati Tags:
Share:

No comments:

Post a Comment

Trending

Popular Posts

Search This Blog

Powered by Blogger.

Featured Post

Coded Statements and Methods

In the preceding procedure , you wrote several coded instructions, which introduced two different programming statements and a method: the D...

Recent Posts