Properties, Methods and Events in Visual Basic 6

This lesson will discuss about the Properties, Methods and Events

Properties, methods and events are 3 separate terms in visual basic but they are associated or interrelated with one another. We will define each and every one of them and give examples as well.

Let’s start the ball rolling.

Properties

It is the attributes of an object or simply defines the characteristics of the object such as color, name of the object, height, and many more. All objects in visual basic (textbox, label, command button, etc.) has its own properties but some attributes/properties are common to most objects like the Visible property which enables you to show or hide the object or control during runtime.


Example:

Following are some of the common properties of an object:

Name is the property in which you can define the name of a certain textbox or controls.

Note: the Name of the object must not be similar to other control (regardless of the object, if that certain name is being assigned to a control, that name can’t be used by another control), no two names are allowed in a form unless you’re going to create an array of that control.

Enabled is the property of a control that allows you to set whether those object can be manipulated or manage during runtime.

Visible is the property of a control which allows you to set whether an object can be seen or not during the runtime.

Object with some of its controls

TextBox has: Name, Alignment, Appearance, Font Color, Height, Enabled, Visible, etc.
CommandButton has: Name, Caption, Font, Enabled, Height, Visible, Width, etc.
Label has: Name, Alignment, Caption, Font, Font Color, Height, etc.

Note 1: you can set the properties of an object in two ways: design time and run time. In design time you can manipulate the properties of an object using the properties window. Visit our lesson about the IDE of Visual Basic to be able to locate the properties window. In the run time, properties of the object can be set using codes.

Methods

Methods refer to actions that the object can perform. Same as properties, all objects have their own methods. Unlike properties, methods can only be manipulated or set using codes.

You can set the methods of an object by using this syntax:

nameOfOject.methodName

Where:

nameOfObject is the name you’ve given to control.
methodName is the name of the method that the object can perform.

Example:

Methods
Methods

 

 

 

 

 

 

 

In our example, the name of the object is CmdClose which is a command button and has a method called Move. Move method changes an object’s position in response to a code request.

Events

Events are associated in a control that triggers something to happen. Events are associated with controls, each control has their own events and some events are common to all controls.

Example:

Events
Events

 

 

 

 

 

 

Form in visual basic has its own events as shown in the image.

Common Events in Visual Basic

Load() event is a type of event that fires or occurs when the form is being loaded.
Click() event occurs when the user presses and then releases a mouse button over an object.
DblClick() event Occurs when the user presses and releases a mouse button and then presses and releases it again over an object.

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.