Programming with the Gambas Basic IDE

Back to Basic

© Eray Haciosmanoglu, Fotolia

© Eray Haciosmanoglu, Fotolia

Article from Issue 95/2008

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.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Realbasic

    Realbasic provides an easy solution for converting Visual Basic programs to Linux.

  • I-Nex System Info Tool

    Thanks to I-Nex, users can see an overview of all their important hardware inventory information, such as graphics cards, processors, and hard drives.

  • I-Nex

    I-Nex is a graphical tool that quickly gives you a detailed overview of the hardware installed in your computer.

  • Custom NimbleX

    If you want customization without all the fuss, then try building your own custom ISO image with the web-based Custom NimbleX Live CD Generator.

  • USB Multiboot Tools

    MultiBootUSB and MultiSystem tools transfer multiple Live systems to a USB flash drive and even install a matching boot manager automatically.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More