Hello guys, I wonder why there are "classes" to use ... but I have no clue why they are used and how to use them.
Sorry, I'm beginner (not in time, but in apps I already composed)
And I'm not English, so please bare that in mind ....
Thanks
what about the classes?
what about the classes?
Vito
born 19 may 1949
using Gambas3 for therapy
on a Manjaro XFCE4 PC
born 19 may 1949
using Gambas3 for therapy
on a Manjaro XFCE4 PC
Re: what about the classes?
In Object Orientated Programming, a class is a kind of template that you can use to create a new "instance" of an "object".
Sounds scary?
When you simply draw a control Button on a form, you use the Button class code to create a new instance (new version/new Button object) of the software that manages a button. This new button object allows you to customise your button with a new name, a new text caption, new size, new colour...and so on.
If we did not have a Button class we all would have to write our own code to draw our own buttons and control how they work ...we would all be re-inventing the wheel!
I'll try to come up with a simple class example with its own Methods (Functions) and Properties.
Re: what about the classes?
Actually, just returning to the Button class may be the best example.
Start a new GUI Gambas project, but don't draw any components on the Form, just add this code to FMain.class:-
We can then use the Button class Properties to set size, colour, text & so on.
Is this helping?
Start a new GUI Gambas project, but don't draw any components on the Form, just add this code to FMain.class:-
' Gambas class file
Public myButton As Button
Public Sub Form_Open()
'create a new instance of the Button Class
'and draw it on the main form (its Parent)
myButton = New Button(FMain)
myButton.Height = 100
myButton.Width = 200
myButton.top = 50
myButton.Left = 100
myButton.Text = "OK"
End
What this code is doing is creating a new button from the existing code class called Button. We call this creating a new instance of the class Button by declaring myButton as a Button.We can then use the Button class Properties to set size, colour, text & so on.
Is this helping?
- cogier
- Site Admin
- Posts: 1129
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: what about the classes?
I have been working on this as well. Here is an example using a class to create a list of your music collection.
The Class may seem a little complicated, but I hope you can see how this small amount of code can do so much.
The Class may seem a little complicated, but I hope you can see how this small amount of code can do so much.
Public Sub Form_Open()
Dim NewAlbum As Record
NewAlbum = New Record(Me, "Sound of Silence", "Simon & Garfunkel", "SoundOfSilence.jpeg", "60s Pop")
NewAlbum = New Record(Me, "Paranoid", "Black Sabbath", "Paranoid.jpeg", "Heavy Metal")
NewAlbum = New Record(Me, "Carpenters", "Carpenters", "Carpenters.jpeg", "Pop")
End
Re: what about the classes?
the carpenters ??? really ???
Re: what about the classes?
yeah ... party
back to topic:
charlie ... i'm an f***ing old procedural programmer with big fears of OOP for a long time and it tokks me a lot of hard work to get into it ... but while understanding how it works or maybe how i should work i will say "oh wow ... how could i program without that" ... taking your second example a newbie would likely say "oh hell ..." but yes it shows what a class can be
vito:
fight your way trough ... programing is fun and you will find solutions for problems that you won't have without programing
you may like to have a look here:
https://gambas-buch.de/dwen/doku.php?id=start
for years now hans lehmann wrote on that and for a starter it is very helpfully, most of it should be in english but also avail in german ... i you have any questions the carpenters and the rest here will try to help you
back to topic:
charlie ... i'm an f***ing old procedural programmer with big fears of OOP for a long time and it tokks me a lot of hard work to get into it ... but while understanding how it works or maybe how i should work i will say "oh wow ... how could i program without that" ... taking your second example a newbie would likely say "oh hell ..." but yes it shows what a class can be
vito:
fight your way trough ... programing is fun and you will find solutions for problems that you won't have without programing
you may like to have a look here:
https://gambas-buch.de/dwen/doku.php?id=start
for years now hans lehmann wrote on that and for a starter it is very helpfully, most of it should be in english but also avail in german ... i you have any questions the carpenters and the rest here will try to help you
- cogier
- Site Admin
- Posts: 1129
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: what about the classes?
I'm beginning to feel unwell...he's only just begun
Re: what about the classes?
Further reading from 12 months ago: https://forum.gambas.one/viewtopic.php?f=4&t=816