Creating a gambas2 program, step by step, a telephone index
From : http://listingambas.blogspot.com/2011/06/antes-de-nada-programacion-de-objetos.html
First of all ... Object Programming:
Properties, Methods
and Events
Gambas is an object-oriented language, i.e. we have some "objects" (buttons,textbox,forms, etc.),
that the user of our program will interact with (by clicking, for example).
Let's
explain with a simple example the concepts of object-oriented programming.
A balloon has properties (color, height and diameter), and respond to events (shot) and can execute methods (Deflate, MakeNoise).
Properties
If you could program a balloon, the code might look like this "code" that sets the properties of a balloon.
Balloon.Color = Color.Red
Balloon.Diameter = 10
Balloon.Inflated = True
Note the order of the code: the object (balloon) followed by his property (color) followed by the assignment of the value (= Color.Red).
You can change the color of the balloon by substituting a different value.
Methods
The methods of a balloon are called this way.
Balloon.Inflate
Balloon.Deflate
Balloon.Makenoise (5)
The order is similar to a property: The object (a name), followed by method (a verb). In the third method, there
is an additional element, called argument
, which specifies the distance at which the balloon will rise. Some
methods have one or more arguments that describe further action to be performed.
Events
The
balloon could respond to an event as follows.
Sub Balloon_Puncture
()
Balloon.MakeNoise
("Bang")
Balloon.Deflate
Balloon.Inflated
= False
End Sub
In
this case, the code describes the behavior of a balloon
when event Puncture
occurs:
MakeNoise method is called with an argument "Bang" (the type of noise
to make), the
Deflate method
is called then. Since the balloon is
no longer
inflated, inflated property is set to False
.
Though
you actually can not program a balloon, you can
program a form or a control. As a programmer,
you are
responsible: decide which properties should
be changed,
which methods to be invoked or events that must be answered, to achieve
the desired appearance and behavior.