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

Ad

Object Properties

A property is a named attribute of an object.  Properties are used to change the appearance and behavior of objects, such as forms and controls.  These properties include attributes affecting the color, size, and name of the object.

Let’s take an everyday object, such as a shirt.  Suppose you write the following:

Shirt.Color = “Blue”

In Visual Basic, this would tell you that you have an object named Shirt. One of the properties of the shirt is color. You can change the color by assigning a new one, such as "Blue". You might want to set the shirt property as

Shirt.launder = “Clean”

as opposed to

Shirt.launder = “Dirty”

In the example, the condition of the shirt – clean or dirty – can be set directly.  Wouldn't it be great if your shirts were always clean?

For a Visual Basic object, such as a form, you can write instructions to alter it.  The following instruction changes the color of a form named Form1 to blue:

Form1.BackColor = vbBlue

Object Methods

The concept of an object method is more difficult than the concept of a property.  Methods are computer instructions (code) held by an object that operate on the object’s data.  Methods are written in a different way than properties.  The syntax (required way) for describing the application of a method to an object is written as follows:

object.Method

Perhaps an analogy will make methods more understandable.  Suppose you had a very compliant dog named Sparkyy.  By invoking the following methods of Sparky, you would get the behavior from Sparky that you desire:

Sparky.eat

Sparky.bark

Sparky.scat

Object methods in Visual Basic are similar.  One method for a List Box control (a control that displays a list of different text items) is the Clear method.  To clear the contents of the list box, you would write the following instruction:

List.Clear

When working with object properties in Visual Basic, you are either assigning them a new value (for example, Form1.BackColor = vbBlue), or you are reading their values (for example, mycolor = Form1.BackColor). Object methods, by contrast, are invoked with the object.Method syntax (for example, List1.Clear).  The distinctions between object methods and object Properties will become familiar to you as you work with Visual Basic objects.

Object Events

While the value of a property can be set and a method can be invoked, an object event is an action taken by the object when notified by a message.  An object event might be a mouse click.  The handling of object events is an operating system responsibility.  The Windows operating system sends messages to windows (objects) for different events.

Remember the words message and action.  If the user clicks a mouse button on a Visual Basic form, the operating system sends a message to the form.  The Visual Basic designer can choose to execute code (the action) in response to the message or ignore it.  For example, an image on a form might be programmed to take some action when it is clicked.  It might take some other action when it is dragged across the form.  The Visual Basic programmer writes coded instructions for the events that should be assigned to the form or control.  Visual Basic code, for instance, executes instructions by invoking a form’s Print method when the user clicks the form.

Private Sub Form_Click()
  Form1.Print "You clicked the form1"
End Sub
Share:

2 comments:

  1. The newer interface for the latest version for Cpanel has addressed the problem of slow load times quite nicely although some things are still hard to find.

    ReplyDelete
  2. hey there, this might be little offtopic, but i am hosting my site on hostgator and they will suspend my hosting in 4days, so i would like to ask you which hosting do you use or recommend?

    ReplyDelete

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