Programming with the Gambas Basic IDE
Back to Basic
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  or wxBasic  showed much promise but didn't survive for long in the wild. KBasic , 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 , 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+  (the underpinnings for Gnome, and XFCE) and Qt  (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 . The system requires several libraries and add-on tools. The installation Help file  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 make su -c "make install"
to build and install the program.
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.
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.
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.
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.
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.
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.
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
Weird data transfer technique avoids all standard security measures.
FIDO alliance declares the beginning of the end for old-style login authentication.
Legendary Uber-distro splits over the systemd controversy.
One of CeBIT’s most successful forums returns in 2015.
A new study says it is possible to unmask 81% of TOR users.
Redmond joins the revolution by turning the .NET Core Runtime into a GitHub project.
Users only had 7 hours to update before the intrusions started.
It's official: The new web arrives