Explanation of terms used in Visual Basic
A short explanation of terms special to Visual Basic.Author: Jens G. Balchen
EventsWe usually react when things happen, and based on what happened, we react differently. To VB, things happen when the user does things. A click with the mouse or a keypress signals that the user is doing something, so VB reacts.
The reaction is called an event. To make VB react like you want it to, there are event procedures. These are pieces of code that VB will run when a particular event takes place.
The Click event must be most widely used event in VB. A typical Click event procedure looks like this:
Sub Object_Click () ' Do something in reaction to this click DoSomething End SubWhenever Object gets clicked, VB will run this code as a reaction to the click.
PropertiesLet's have a look at an ordinary bottle. A bottle usually has a label, it has a screw cork, it's made of glass or plastic, it contains something, and it has a shape. These are all properties of the bottle.
A property describes an object, its behaviour and its look. If we were to change the look of the bottle, we'd change the shape property, like this:
Bottle.Shape = CONE ' Make Bottle cone shaped Bottle.Shape = CYLINDER ' Make Bottle cylinder shapedIf we wanted to change the label, we could do that too. The nice thing about properties is that you do not have to know what it takes to actually change the bottle's shape or label. You just indicate that you want it to change. A good example is the Text control.
The Text control has an important property, Text. The Text property sets or returns the text presently contained in the Text control, but it does so without us having to know how the text is shown on the screen, or how the user can scroll back and forth inside the control.
TextControl.Text = "Properties are great" ' Set Text control text MsgBox TextControl.Text ' Display text currently in Text control
MethodsSometimes, properties aren't enough to tell an object what it should do. It would be nice to give the object direct commands as well. If we consider our bottle again, we could want to empty the bottle to fill it with something else. A method is a nice way of doing that. The bottle could have a method called
Bottle.EmptyYourSelfAs you see, we don't give a method a value, we execute it like any other VB command. As far as we're concerned, we don't care what the bottle has to do to empty itself (it can flip itself up-side down, it can drill a hole in itself, etc.). All we want is for it to empty itself.
Methods aren't widely used. Until recently, software companies couldn't provide their VBXs with methods, and few VB controls use methods. But they are very useful. With VB 4.0, the limitations imposed on software developers with regards to methods have been removed, so you can expect to notice a lot of custom controls (VBXs or OCXs) with a wide range of methods)
Editor: Jens G. Balchen
Last update: 2020-02-29
Copyright 1995-2020 VBI