Skip navigation
Banner: GambOS Alpha 3 released
"Don't let the noise of others' opinions drown out your own inner voice. And most important, have the courage to follow your heart and intuition."
Hello, Guest!

Welcome to Quin's Corner

Many of the questions I've seen raised on the forum are not so much about specific Gambas issues; but more around coding in general and some of the bugs in submitters entries have been introduced by less than optimal structure in their written code.

These articles will contain information on how to plan, structure and write application code that is robust and easy to maintain in the long term.

Guest, if you have questions, just start a post on the Ask Quin forum and I'll be more than happy to answer general questions on how to structure your code and will write replies in the newsletter for some of the common questions.

Special note to "Newbies". We were ALL Newbies once, and my philosophy is that:"there is no such thing as a dumb question", so don't feel that you are alone in your quest to learn how to do things. Ask ! It's the best way to learn.

Modules 101


Quincunxian in the usergroup ‘WIKI Editor’
Quincunxian in the usergroup ‘Community Saint’

What are Modules ?

A Module is a object in Gambas that contains variables and subroutines that are available to your entire project.

Like a normal class, you must create the variable or subroutine as PUBLIC for it to be accessable to your project code.
PRIVATE variables and subroutines are only accessable from within the Module that they are created in.
However, unlike other programming languages such as Visual Basic .Net and C++, in Gambas you must also reference the Module name to access the variables.

If you have a global variable called ApplicationName that you want to use in your project you would declare it as PUBLIC in your Module.

Create a Module and name it "mGlobal"
add the line :


PUBLIC ApplicationName as String = "My Application Name"

Then, in your other forms or classes, you referency this by writing mGlobal.ApplicationName
For example: on the Form_Open event for each form, you can add the following line:


Me.Text = mGlobal.ApplicationName & " Ver: " & Application.Version

This will provide a consistant name and application version text for all of your forms.
Now if you want to change the name of your application, you only have to do it once in your module !

You can also have reference to Classes in your module.

Create a Class called "cMyDetails" and declare the follwing variables.


PUBLIC MyName as string = "Fred Bloggs"
PUBLIC Age as Integer = 21
PUBLIC EMail as String = ""

Now in your Module, add the following:


PUBLIC MyDetails as New cMyDetails

Now anywhere in your project you can reference your EMail address using the variable



You can have more than one module in your project and even have the same variable name in each.
For example:
Create a module called "mSQLITE" with the following code:


PUBLIC $Con as Connection

PUBLIC SUB InitialiseDataBase()
   $Con = New Connection
   $Con.Type = "sqlite"
   $Con.Name = "mydatabaseName"

Create a Module called "mMySQL" with the following code:


PUBLIC $Con as Connection

PUBLIC SUB InitialiseDataBase()
   $Con = New Connection
   $Con.Type = "mysql"
   $Con.Name = "mydatabaseName"
   $Con.Password ="SomePassword"
   $Con.User = "SomeUserName"

Now you can initialise the database connection by calling the appropriate module and function.

mSQLITE.InitialiseDataBase OR mMySQL.InitialiseDataBase
Both have the $Con variable declared but as they are declared in different modules, they is no naming conflict.

So you can reference the database name for each connection as:

What sort of things do I put in Modules ?

Any variable or constant that you want to be accessable throughout your entire project.

Any Subroutine or Function that is generic for your entire project.

For example:
You want to give all your sub froms the same look and feel when they open.
Enter the following code into your "mGlobal" module


Public Sub OpenSubForm(InText As String, ByRef InForm As Form)

   InForm.Text = InText
   InForm.SkipTaskbar = True


Now in your main form when you open a sub form, instead of using:




It will centre the sub from on the screen, add some descriptive text to the title bar and NOT display it in the Taskbar.
Note # The sub form is passed to the subroutine ByRef so any changes that we make to the form affect the actual form passed.

Happy coding.

Read more 0 comments

Design Principles - Before you sit at the keyboard !


Quincunxian in the usergroup ‘WIKI Editor’
Quincunxian in the usergroup ‘Community Saint’

Greetings all,

I'm currently helping Conrad, an enthusiastic but self confessed Newbie to Gambas, to work on an exciting project to do with Home Automation.
While Conrad's requirement is around some rather large scale water irrigation for his property, the same design principles and problems apply to
anyone who is thinking about starting a medium to large project.

I'll keep everyone informed about how this specific project progresses as I'm sure that there are a lot of members who would like to do some work with
Gambas and automation control - It's a learning journey for me as well so I'll post up in general forum as things come to hand.

Scoping document.
All large formal projects start with a scoping document.
This outlines what you expect to achieve with your project and lists the 'objectives'.
It can list data sources, table fields, what screen displays look like, the number of forms, any special classes that you have to write….
This does not have to be a "War & Peace" document, just a single page will sometimes do; but it is good to refer back to
so that you don't suffer from what is know as 'Scope Creep'.
Some block diagrams with a few notes in a notepad is all it needs to be; but what you need to do is stick to the outcome !
Often, as you start to write things down, you have that "Mmmmm how the hell am I going to make that work" moment.
This can save you a lot of wasted time and while this appears obvious when written down, you would be surprised how many professionals
fail to do this well.

The Evil of 'Scope Creep'
I must admit that I'm not immune to this horrible beast :$ and I have to keep reminding myself that I need to keep the original goal in mind and not add
'Oh that's so cool, I'll just add that as another feature', again and again and again……
Scope Creep = never really finishing a project and it gets so out of hand that you end up giving up on what was originally a great idea.
The other important thing to note, is if you are writing a program for someone else, this scoping document ensures that they don't keep
adding features to the work in progress (WIP) and you end up with the "Never Ending Project"
(Please note that Conrad's not doing this :P, but it was a good common issue worth mentioning.)

Version X
As part of your scoping document, you can include a page for 'Version X' notes.
You can quickly jot down the great ideas you have as you are writing the code for your application in a list for the NEXT version
and then when the times comes to being work, you already have a good idea of what the NEW Scope is, how it relates to the code that you
have already created and this will help you to ensure that you don't end up with 'Spaghetti Code' See Spaghetti_codeon Wikipedia
Please read this short description of code types, as it covers some very interesting points.


Read more 0 comments