Programming with the Gambas Basic IDE

Back to Basic

© Eray Haciosmanoglu, Fotolia

© Eray Haciosmanoglu, Fotolia


Gambas is a fast and easy tool for writing graphical desktop applications in Basic.

If you owned a home computer in the 1980s, you are probably familiar with the Basic programming language. Basic survived into the age of the Windows PC; however, the language was never as popular on Linux, which comes with several powerful alternatives. Projects such as HBasic [1] or wxBasic [2] showed much promise but didn't survive for long in the wild. KBasic [3], which was originally designed to provide a Basic environment for KDE, still exists as a commercial program for Linux, Mac OS X, and Windows. RealBasic is another commercial, closed source development environment for Linux, Windows, and the Mac OS.

One free alternative for Basic in Linux, Gambas [4], has continued to gain ground in the past few years and has gathered quite a large developer community. Designed as an integrated development environment, Gambas helps developers write programs with a graphical user interface. It supports the deployment of Gtk+ [5] (the underpinnings for Gnome, and XFCE) and Qt [6] (the basis for KDE). Gambas currently supports Qt 3, but not the more recent Qt 4. The IDE runs on Linux only, and the roadmap does not currently include ports to other operating systems.

The developers place much emphasis on making sure no one sees Gambas as a Microsoft Visual Basic clone, from which it differs in various details. However, if you have previous knowledge of Visual Basic, you should have no difficulty finding your way around Gambas – especially considering the documentation explains the differences between the two languages.

The developers completed Gambas 2.0 early in 2008 after four years of work; development has been rapid since then. In early April, version 2.5.0 introduced enhanced stability and a number of improvements. Gambas now runs natively on 64-bit systems, unlike version 2.0. In this article, I refer to version 2.5.0 throughout (see the box titled "Installation").


Gambas is available as a source code archive from the project's SourceForge page. The prepackaged binary includes a number of tools, which you can install via the distribution's own package management system [7]. The system requires several libraries and add-on tools. The installation Help file [8] lists the required programs and provides a HOWTO for the installation on Ubuntu, Mandriva, openSUSE, and Debian. It is important to resolve dependencies to avoid compromising the functionality of Gambas.

If your target system fulfills the dependencies, you can start with the ./reconf-all command in the Gambas source code directory. Then, at the command line, type

./configure -C
su -c "make install"

to build and install the program.

First Start-Up

When you launch Gambas, you will see a dialog that lets you open an existing project or create a new one (Figure 1). A list of recently modified projects appears on the right side of the dialog.

Figure 1: The Welcome screen lets you choose an existing project or create a new one.

If you decide to create a new project, a wizard walks you through the required settings in three steps (Figure 2). The first step is to choose the project type. Gambas lets users develop graphical programs with either the Qt toolkit or Gtk, command-line programs, and CGI applications. If necessary, Gambas will also integrate components for database access or image manipulation.

Figure 2: Gambas includes a wizard to help users set up projects.

If you decide on a Graphical application project, Gambas will use either the Qt or Gtk toolkit, depending on your desktop – in other words, it adapts to match your choice of environment. The files, forms, source code, and graphics belonging to a project are stored in a directory named for the project.

After selecting or creating a project, go to the main window to write program code (see Figure 3). At the left margin of the window is a panel that displays the files, source code, forms, icons, and other graphics and classes belonging to the project. The documents are stored in a tree structure. Double-clicking an element opens it in the workspace at the center of the program window. By selecting View | Project, you can display the sidebar.

Figure 3: The Gambas interface offers easy access to a well-organized toolset.

Below the workspace, you will see the Console, where the debugger runs and where you can manage breakpoints. At the top right side of the program window, you will see the Properties window, where you can configure the properties of the selected interface objective.

Below this is a Toolbox with controls for designing graphical interfaces.

The Gambas source code editor has all the functionality you would expect from this kind of program: Syntax highlighting is helpful, as are functions for hiding and displaying code blocks, and auto-completion is available. This means you can click to hide a whole program section. Just as with other editors, the software lets you tile the window horizontally or vertically.

The form editor has the usual controls, which you can position precisely on the desktop thanks to a grid. A menu editor facilitates menu design. Selecting Menu editor… in the drop-down menu for a form, or pressing Ctrl+E, launches the editor (Figure 4). The editor allows programmers a way to manipulate, move, or nest menu structure elements. Keyboard shortcuts are also easily defined.

Figure 4: A menu editor helps developers create comprehensive menu structures, including keyboard shortcuts.


Depending on your choice of toolkit, the toolbox will offer you a number of different widgets. The usual suspects, such as text boxes, labels, selection boxes, and buttons, are predefined, as are image and video boxes for displaying corresponding content. Date and time selection dialogs, color pickers, and directory, file, and font managers complete the toolbox.

An HTML output control lets programmers create a miniature browser for HTML-based Help texts in next to no time (Figure 5). Gambas includes a sample program on which you can base your own projects.

Figure 5: Gambas helps users create a simple HTML browser in next to no time.

Mastering Databases

Gambas supports access to various databases and database servers. The IDE offers controls for connecting to MySQL and PostgreSQL. Support is available for file-based SQLite, SQLite2, and SQLite3 databases, as well as for ODBC access. To facilitate database access, Gambas includes a Database Manager, which lets users manage connections to various servers and data repositories. To open the manager, select Tools | Database Manager (Figure 6) in the menu.

Figure 6: The Database Manager facilitates access to databases and database servers.

The wizard prompts you to enter the administrator password for the server before going on to contact the host. Databases are listed in a tree structure on the left of the manager window. The program helps you set up and modify tables, SQL queries, and database users.

After establishing the database connection, access to the database itself is simple: Gambas gives you several database access controls, which you can simply drop into a form. The widgets are available in the toolbox's Data tab.

The DataBrowser lets you scroll inside a database table. The elements also let users add and delete records. To do so, it displays a toolbox with buttons for navigating the data, creating records, and deleting records.

The DataView element adds the ability to create tables from the data, whereas the DataCombo element provides a combobox that lets users select a record from a table on the basis of a single field. Gambas has a very intuitive approach to widget deployment, a fact that really takes the pain out of database-enabled applications.

Distributing Programs

Programs you create with Gambas need the Gambas Runtime Engine on third-party machines. If you intend to distribute your software, the target system must have a run-time engine. Gambas provides an installation package wizard to help you set this up for your users. To launch the wizard, select Project | Make | Installation Package.

The wizard starts by prompting you for details on the author and a short description of the program. The version information and changelog are entered in Step 1. Gambas then creates installation packages for various distributions (Figure 7). As of this writing, the supported distributions are Fedora, Mandriva, Debian, Slackware, and Ubuntu. Packages created by the wizard can be installed and uninstalled by the distribution's native package management system.

Figure 7: Gambas provides a wizard to help you create installation packages.

Help and Support

Gambas has online Help with a command reference. Entries for commands and constants have examples that clarify usage. For those who prefer to learn a programming language by following examples, the IDE includes a number of ready-made projects that illustrate the use of various components.

To access the sample files, select File | Open examples…. The examples are sorted by group and are all very simple. In addition, the comments in the source code help budding developers follow the logic.

A number of sample programs available online [9] provide a good starting point for building your own creations. However, some of the programs are fairly ancient. The tutorial created by the developers [10] is also a useful place to start your Gambas programming career. It guides you step by step through the development environment's functions, with an introduction to critical programming techniques.

The Gambas wiki [11] includes installation HOWTOs, a directory of error messages, and an up-to-date command reference. The comprehensive and very readable wikibook [12] for Gambas only covers version 1 of the environment.

For the most part, the documentation lacks support on advanced programming topics, such as how to develop custom components or more complex database programs.


Gambas offers a sensible user interface and an easy-to-learn programming language that let you develop simple graphical applications with a very short learning curve. It includes comprehensive support for various database types and lets programmers quickly and easily build front ends for database applications.

The program is now more than stable enough for production use. Version 2.0 suffered from a number of bugs and crashed fairly frequently, but version 2.5 has removed these failings.

Right now, Gambas needs updated documentation to make it more comprehensive.

Although some useful tutorials are available on the web, you won't find much information on advanced programming techniques.