Fact-checked by Grok 2 weeks ago

Gambas

Gambas is a free and open-source object-oriented dialect of the language, accompanied by an () that facilitates graphical application development, primarily for and other operating systems. Developed by programmer Benoît Minisini since 1999, it draws inspiration from while incorporating modern object-oriented features like inheritance and polymorphism, and is released under the GNU General Public License. The name "Gambas" is a playful standing for "Gambas Almost Means ," reflecting its roots in the accessible syntax of interpreters. The project began as an effort to create a Visual Basic-like tool for , with the first public release occurring in 2002 and version 1.0 in 2005; subsequent major versions include Gambas 3 (2012) and the current stable series, Gambas 3.21.0, released in late 2025. Gambas supports a compact with approximately 250-350 keywords and functions, enabling rapid development of desktop applications through its visual form editor, syntax-highlighted code editor, and built-in . Key components include a that processes code at high speeds (around 920,000 lines per second on modern hardware), an interpreter for runtime execution, and libraries for GUI toolkits such as and , as well as database connectivity to systems like , , and . Notable features emphasize ease of use for beginners and power for advanced users, including full support, tools, process control, error management, and scripting capabilities, allowing applications to integrate seamlessly with desktop environments like , , and . Gambas programs can be packaged for distribution via formats compatible with , , and other repositories, and it extends to cross-platform potential through efforts for , , and even Windows via or . With over 860 classes and 10,000 symbols in its , Gambas remains a lightweight yet versatile platform (interpreter size ~654 KB on 64-bit systems), actively maintained to support contemporary development needs in ecosystems.

Introduction

Overview

Gambas is an object-oriented of the language, accompanied by an () designed for . Developed by Benoît Minisini, development of which began in 1999, with the first public release in 2002 as a free and open-source alternative inspired by , targeting graphical desktop applications on and other operating systems. The language compiles to for interpretation, enabling quick prototyping due to the fast compilation process (around 920,000 lines per second on modern hardware), while the provides tools for visual design, debugging, and project management. Key characteristics of Gambas include its support for GTK+ and toolkits, allowing developers to create cross-compatible graphical user interfaces. It features over 860 built-in classes and components that facilitate multimedia handling via and , database interactions with systems like , , , and ODBC, as well as networking protocols including and . These elements promote with and polymorphism, all within a BASIC-like syntax for . As of November 2025, the current stable version is Gambas 3.21.0, which introduces enhancements such as optimized processing up to 20 times faster, improved just-in-time () compilation for better interpreter speed, and various bug fixes addressing memory issues and debugger stability. These updates refine the platform's performance and reliability for modern application development.

Etymology

The name Gambas serves as a for "Gambas Almost Means BASIC," underscoring its roots as an object-oriented of the programming language. This construction was devised by Benoît Minisini, the developer who created the project in 1999, to playfully nod to its BASIC heritage while distinguishing it as a modern evolution. The term "gambas" also carries a linguistic , as it translates to "" or "" in , , and . Minisini selected this name to infuse humor and whimsy, evoking the lightweight and approachable nature of seafood as a for the language's simplicity and ease of use. Through this etymological choice, Minisini aimed to position Gambas as a fun, accessible open-source alternative to proprietary tools like , emphasizing an inviting entry point for developers seeking straightforward programming on and systems.

History

Origins

Gambas was conceived by Benoît Minisini, a from the suburbs of who had been passionate about programming since childhood, beginning with on computers like the and Atari 520 STE at age 12. Minisini's early experiences with shaped his affinity for simple, accessible languages, but by the late , he grew frustrated with the absence of a -like tool for , where rapid (GUI) development was cumbersome compared to Windows environments. The initial motivation for Gambas stemmed from Minisini's desire to create an open-source, Linux-native alternative to Visual Basic, enabling quick application without proprietary dependencies or the quirks of the original. He envisioned a complete environment inspired by BASIC's ease but extended with object-oriented features, akin to or .NET, to meet his personal needs for visual and straightforward programming. As a solo project, Minisini began by sketching ideas on paper before implementing the core components in 1999, starting with a and a simple form designer to facilitate immediate prototyping. The first release occurred in 2002. Early posed significant challenges, as Minisini built everything from scratch to ensure independence from , initially focusing on the toolkit for cross-platform support while prioritizing coherence and reliability for users.

Version Timeline

Gambas achieved its first stable release with version 1.0 on January 10, 2005, marking a milestone in providing basic stability for creating graphical user interfaces and applications on systems. This version established the core interpreter and framework, enabling developers to build Visual Basic-style programs with improved reliability over earlier prototypes. The release of Gambas 2.0 in early 2008 represented a significant advancement, with enhancements to capabilities and expanded component libraries that facilitated more complex application development. This version refined the language's syntax and integration with external libraries, broadening its appeal for desktop software creation. A pivotal shift occurred with Gambas 3.0 in January 2012, which underwent a major rewrite to boost performance through optimized bytecode interpretation and increased in its component architecture. This overhaul allowed for better extensibility and efficiency, laying the groundwork for subsequent iterative improvements in the 3.x series.
VersionRelease DateKey Developments
3.19.0February 16, 2024Interpreter optimizations for faster execution and reduced memory usage.
3.20.0Early 2025Enhancements to the development environment, including improved tools and updated packaging support.
3.21.0October 13, 2025Bug fixes across components, along with initial Qt6 support for modern GUI rendering.
Over the course of its evolution, Gambas transitioned from exclusive reliance on the toolkit in early versions to dual support for both and starting in the mid-3.x series, enabling greater compatibility with diverse desktop environments like and . Additionally, later 3.x releases introduced experimental Just-in-Time () compilation, beginning with version 3.12.0, to accelerate code execution by translating Gambas to native on the fly. As of November 2025, the project remains actively developed under Benoît Minisini's leadership, with efforts progressing toward a potential Gambas 4.0 that prioritizes expanded cross-platform capabilities, including better Windows and macOS integration via ongoing component refinements; however, no firm release date has been set.

Language Features

Syntax and Core Elements

Gambas employs a BASIC-like syntax that emphasizes readability and simplicity, featuring keywords such as PRINT for output, IF...THEN...ELSE for conditional statements, and FOR...NEXT for iteration loops. The language is case-insensitive for keywords and identifiers, allowing developers to write Print or print interchangeably while maintaining consistency in code style. This design draws from traditional BASIC dialects, enabling straightforward procedural programming without mandatory semicolons for statement termination or explicit type declarations in all cases. Core data types in Gambas include the for dynamic typing, which can hold any value and defaults to NULL, accommodating automatic similar to . Other fundamental types encompass (32-bit signed, range -2,147,483,648 to 2,147,483,647, default 0), (variable-length , default NULL), (true/false, 1 byte, default FALSE), and (8 bytes for date and time, default NULL). Conversion between types occurs seamlessly via built-in functions like CInt, CStr, and CBool, facilitating flexible data handling without explicit casting in many operations. Control structures support modular code organization through subroutines, declared as PUBLIC SUB or PRIVATE SUB for accessible or module-restricted procedures, respectively, with optional typed parameters (e.g., AS String). Error handling utilizes a TRY...CATCH...FINALLY block, where TRY encloses potentially erroneous code, CATCH processes exceptions, and FINALLY ensures cleanup execution regardless of errors. Arrays are declared using DIM, such as DIM arrayName AS New Type[dimension], supporting multi-dimensional structures with zero-based indexing. Built-in functions provide essential operations, including string manipulation with Left$ (extracts prefix characters), Mid$ (substrings), and InStr (substring position); mathematical utilities like Abs (absolute value), Sqr (square root), and Max (greater of two values); and basic file I/O via OPEN (file access), LINE INPUT (line reading), and CLOSE (resource release). A distinctive feature is event-driven programming support, where custom events declared with EVENT are triggered using RAISE EVENT, optionally returning a boolean to indicate handler cancellation.

Object-Oriented Capabilities

Gambas provides robust support for through its class-based system, where serve as blueprints for creating objects that encapsulate data and behavior. An object in Gambas is instantiated using the NEW operator and consists of , variables, methods, and , allowing developers to model real-world entities effectively. is implemented via the Inherits keyword, enabling a to derive from a parent and inherit its methods, , constants, and , with a maximum inheritance depth of 16 levels to prevent excessive hierarchies. This mechanism promotes , as child classes can override inherited methods to provide specialized implementations while maintaining compatible signatures, thus supporting polymorphism through virtual method dispatching. For example, a derived class can redefine a parent's Draw method to handle specific rendering without altering the base behavior elsewhere in the program. Encapsulation is achieved primarily through visibility modifiers for methods and variables: Public (the default, accessible from outside the class) and Private (restricted to within the class only), ensuring internal state management while exposing necessary interfaces. Properties, however, are always public, providing controlled access to data via getter and setter methods if needed. This design hides implementation details, reducing complexity and enhancing maintainability in larger projects. Built-in classes number over 100, including the Collection class for dynamic key-value storage, Stream for input/output operations, and Timer for handling asynchronous events like periodic tasks. These object-oriented features integrate seamlessly with Gambas components, which are reusable class libraries extending core functionality; for instance, the gb.db component provides classes for database connectivity to systems like MySQL and PostgreSQL, while graphics components such as gb.qt offer classes for UI elements and rendering.

GUI and Component Integration

Gambas facilitates the creation of graphical user interfaces through its integrated development environment, which includes a visual form designer enabling developers to build forms using a drag-and-drop interface for widgets such as buttons, textboxes, labels, and other controls. This designer allows for intuitive placement, resizing, and alignment of elements on forms, streamlining the process of prototyping and refining user interfaces without manual coding for layout. The designer supports properties editing panels for customizing appearance, behavior, and data binding directly within the IDE, promoting rapid application development similar to traditional BASIC environments. Event handling in Gambas GUI applications is tied directly to controls via a convention-based system, where developers define methods named after the control and event, such as Button1_Click() for responding to a button click or TextBox1_Change() for detecting text modifications. These events, including Click, Change, KeyPress, and MouseDown, are raised automatically by the underlying toolkit and executed in the context of the form's class, allowing for responsive, event-driven programming. This approach integrates seamlessly with Gambas's object-oriented features, where controls are instances of classes that can inherit and extend event behaviors. The component system in Gambas extends GUI capabilities through pre-built, loadable libraries that provide specialized classes for common tasks, enhancing integration without requiring external dependencies. For multimedia, the gb.media component offers classes like VideoPlayer for playback of audio and video files using GStreamer, supporting formats such as MP4 and WAV. Networking is handled by the gb.net component, which includes classes for HTTP requests via HttpClient, socket communications with Socket, and email via SmtpClient. Database integration is supported by gb.db, enabling connections to systems like MySQL, PostgreSQL, and SQLite through unified classes such as Connection and Result, abstracting vendor-specific details for SQL operations. These components are selected in the project settings and compiled into the application, ensuring modular and extensible GUI development. Gambas achieves cross-toolkit support for GUIs via an in its gb.form and related components, allowing developers to write toolkit-agnostic code while selecting the underlying implementation at . The gb.gtk component leverages GTK+ version 3 for native integration on GNOME-based desktops, providing widgets with theming and accessibility features. Alternatively, gb.gui.qt dynamically loads Qt5 or Qt6 based on the runtime environment, such as , offering high-performance rendering and advanced effects like animations. This selection is configured in the project properties, ensuring compatibility across desktops without code changes, though performance and appearance may vary slightly between toolkits. For deployment, Gambas compiles projects into standalone using the gba3 archiver, which bundles from forms, classes, and modules into a single marked as . The resulting application embeds the Gambas interpreter via memory-mapped access to the archive, eliminating the need for a separate runtime installation and enabling distribution as self-contained binaries on systems. This process preserves information if needed and supports icon embedding for desktop integration, facilitating easy sharing and execution of applications.

Development Environment

IDE Structure

The Gambas (IDE) features a modular layout centered around several key components that facilitate , authoring, graphical , and . The primary includes a and at the top for , a Project Browser (also known as the Project Explorer) on the left displaying a of project files such as forms, modules, classes, and resources, and a central workspace for editing forms or . This structure allows developers to navigate and organize projects efficiently, with the ability to switch between and views seamlessly. The code editor, integrated into the central workspace, provides for Gambas BASIC code and auto-completion suggestions based on language keywords, class members, and project-specific elements to streamline . When event handlers or procedures, the editor supports indentation, underlining, and context-aware prompts, enhancing during . The form designer, also in the central area, enables drag-and-drop placement of controls from a built-in toolkit (e.g., buttons, labels, text boxes), with resizing handles, alignment tools, and a properties panel for configuring attributes like position, size, and s. This visual tool is particularly suited for of graphical user interfaces. The , accessible via toolbar buttons or keyboard shortcuts like F5 for execution, offers breakpoints, variable inspection, tracing, and runtime highlighting directly within the , allowing step-by-step . In version 3.21.0 (released November 2025), the panel can be undocked and placed on another screen, and it highlights values that have changed. Gambas supports multiple project types, including console applications for text-based programs, graphical applications with form-based UIs, and libraries for reusable code modules, selectable during project creation. Projects are organized hierarchically in the Project Explorer using modules for grouping procedures and functions, and classes for object-oriented structures, enabling modular development and easy file management without imposing rigid hierarchies. Built-in tools include an incremental compiler that translates Gambas source code into architecture-independent bytecode for efficient execution, an interpreter console for interactive testing of code snippets in console projects, and an integrated profiler introduced in version 3.2 for analyzing performance metrics such as execution time and function calls. These tools are invoked directly from the IDE's menus or toolbars, supporting a streamlined workflow from writing to optimization. Customization options encompass editor color themes that adapt to system dark mode preferences for better visibility, and extensibility through the component system, where developers can load plugins as shared libraries (e.g., gb.qt for Qt-based GUIs) to add new classes or features without modifying the core . An integrated help browser provides context-sensitive documentation, including class references and examples, accessible via F1 or menu navigation to assist during development. integration includes basic support added in version 3.20, with enhancements in 3.21.0 (November 2025) for committing individual files and cherry-picking commits, enabling repository pulls, pushes, and options like rebasing directly from the IDE's project menu.

Tools and Workflow

The development workflow in Gambas typically begins with creating a new through the , where developers select a project type such as a graphical application or console program. Forms and user interfaces are then designed visually using drag-and-drop tools, allowing components like buttons and text fields to be placed and configured without manual coding for layout. Event-driven code is written in response to user interactions, such as button clicks, leveraging the 's code editor for and auto-completion. The is subsequently compiled and tested within the , with options to run in debug mode or generate a standalone for distribution. Debugging tools in Gambas include setting breakpoints by pressing F9 on a line, which pauses execution for inspection, and watches that monitor expression values, stopping the program when changes occur. Step-through execution is supported via shortcuts such as F8 for single-stepping into , F5 for running or continuing execution, and SHIFT + F5 for running to the current line, enabling precise traversal of paths. An error console displays runtime outputs, including , , and messages, along with traces for unhandled exceptions to facilitate rapid issue identification. For testing and profiling, Gambas provides the gb.test component, a framework for and that allows creation of automated test suites to verify program functionality. Profiling tools, enabled via the IDE's "Debugging > Enable Profiling" menu or the .Profile property, analyze runtime performance by measuring memory usage, complexity, and function call frequencies and durations, with results saved to a profile file limited to 512 by default. Collaboration features support exporting projects as .gambas archive files for sharing via or , and importing them into other instances of the to continue development. Components can be shared through the Gambas contrib directory in the source or by packaging them as installable libraries, allowing reuse across projects without full source disclosure. Best practices in Gambas emphasize by encapsulating functionality into reusable classes and modules to promote maintainability and . Developers should also account for cross-platform differences, such as varying environments, by testing on multiple supported systems and using conditional compilation directives where necessary.

Availability

Supported Platforms

Gambas primarily supports distributions, where it is available through native packages for major releases such as 20.04, 22.04, 24.04, and 24.10; 11 and 12; ; and Leap 15.6; ; and . It compiles and runs reliably on these systems, leveraging the standard package managers like APT, DNF, or Pacman for straightforward integration. and provide packages through their standard repositories. Support extends to other Unix-like operating systems, including , , and , where Gambas 3 compiles successfully, though some components like gb. may require adjustments. has experimental ports, but functionality remains unconfirmed, while macOS has limited support; compilation is not officially supported and may encounter stability issues. Windows lacks native support; however, experimental compatibility is achieved through or (WSL), allowing Gambas to operate in a Unix-like environment. Gambas targets common architectures including x86, , and , with dedicated ports enabling deployment on devices like the for applications. There is no official support for mobile platforms such as or as of 2025, due to limitations in the underlying C library features required for compilation and execution. The runtime environment depends on graphical libraries such as GTK+ (version 2.16 or 3.4) or (version 4.5 or 5.3) for development, alongside core dependencies like libffi and for rendering. These ensure with desktop environments while maintaining a minimal installed footprint, typically under 50 MB for the core interpreter and essential components on Debian-based systems. Gambas supports cross-compilation, permitting the creation of standalone Linux executables on other Unix-like systems using tools like the built-in compiler, which generates native binaries without runtime dependencies beyond standard libraries. This facilitates development workflows across compatible environments, with installation methods detailed separately via distribution repositories.

Installation Methods

Gambas can be installed via binary packages, which are the recommended method for most users on supported Linux distributions, as they handle dependencies automatically. Binary packages are provided through distribution repositories or official builds hosted on the openSUSE Build Service. For Debian-based systems like Ubuntu, users can add the appropriate repository and install using the package manager; for example, on Ubuntu 24.04 or later, add the stable repository with echo 'deb http://download.opensuse.org/repositories/home:/gambas:/stable/xUbuntu_24.04/ /' | sudo tee /etc/apt/sources.list.d/home:gambas:stable.list, import the signing key via curl -fsSL https://download.opensuse.org/repositories/home:/gambas:/stable/xUbuntu_24.04/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/home_gambas_stable.gpg > /dev/null, then run sudo apt-get update followed by sudo apt-get install gambas3. Users should select the repository path matching their specific Ubuntu version from the openSUSE Build Service. Similar steps apply to other distributions such as Arch Linux, openSUSE, and Debian, where repositories are added to pacman.conf, zypper, or apt sources, respectively, before installing the gambas3 package. For newer versions on Ubuntu, a Personal Package Archive (PPA) may be available, such as the Gambas stable PPA, to access updates beyond the default repositories. Source tarballs for stable releases are also downloadable from SourceForge, though compilation is required after extraction. For users needing the latest development features or custom builds, installation from source code is possible by cloning the Git repository from GitLab. Prerequisites include development tools like gcc, g++, automake (version 1.11.1 or later), autoconf (version 2.68 or later), libtool (version 2.4 or later), and libraries such as libffi-dev, libbz2-dev, libcairo2-dev (version 1.6.0 or later), with exact dependencies varying by distribution and listed in the project's .gitlab-ci.yml file for reference. After installing prerequisites—for instance, on with sudo apt-get install build-essential g++ automake autoconf libtool libffi-dev libbz2-dev libcairo2-dev and additional libraries as needed—clone the repository using git clone https://gitlab.com/gambas/gambas.git, navigate to the directory, run ./reconf-all to generate configuration scripts, then ./configure -C (optionally with flags like --enable-nonfree for certain components), followed by make -j$(nproc) for and sudo make install for . Stable versions can be obtained as tarballs from the official website instead of Git for a release-specific build. Version management in Gambas distinguishes between stable releases (e.g., 3.21) available via binary packages or tagged commits, and development branches from the master, which may introduce experimental features but require recompilation for updates. Distributions typically provide stable versions through their package managers, allowing seamless updates with commands like [sudo](/page/Sudo) apt-get upgrade gambas3 on Debian-based systems, while users pull changes with [git](/page/Git) pull before rebuilding. Post-installation setup involves launching the Gambas with the gambas3 command and configuring GUI toolkits if needed for development. Gambas supports both and toolkits for creating graphical user interfaces, selectable during project creation in the or by including specific components like gb.gtk or gb.qt. Additional contrib components, such as extensions for databases or web views, can be downloaded directly within the using the built-in component manager under the Tools menu, which connects to the online repository hosted on the project's servers. No further system-wide configuration is typically required, as toolkit dependencies are resolved during . Common installation issues often stem from unresolved dependencies on older distributions, where missing libraries like libgtk-3-dev or qtbase5-dev prevent or runtime errors occur. Troubleshooting involves running sudo apt --fix-broken install on Debian-based systems to repair package conflicts, verifying and installing all prerequisites from the .gitlab-ci.yml , or enabling / repositories in with sudo add-apt-repository universe before retrying. For source builds on legacy systems, users may need to adjust configure flags or use a containerized to match supported platforms.

Adoption and Community

Usage and Impact

Gambas primarily appeals to a niche of hobbyists, educators, and small-scale developers who value its accessible BASIC-inspired syntax for creating graphical user interfaces on systems. This targeted adoption stems from its design as a lightweight alternative to more complex environments, enabling quick prototyping without steep learning curves. The language's impact lies in bridging the gap for BASIC-style (RAD) tools on open-source platforms, where it supports () in an intuitive manner. In educational contexts, Gambas serves as an effective entry point for teaching principles and GUI design to novice programmers, fostering hands-on learning through its . Adoption has remained steady yet gradual, with some interest in integrations for hobbyist electronics and embedded projects. This reflects Gambas' compatibility with architectures, allowing seamless deployment in low-resource scenarios like prototypes. The release of Gambas 3.21.0 in late 2025 continues to support ongoing community engagement. Despite these strengths, Gambas' ecosystem lags behind established languages such as or , resulting in minimal commercial uptake and reliance on community-driven components. Its user base is a small but dedicated worldwide, gauged from and patterns, underscoring its role as a specialized rather than mainstream tool. Metrics include over 10,000 cumulative posts across dedicated communities and consistent activity on hosting platforms like .

Resources and Projects

The Gambas project maintains several official resources to support developers and users. The Gambas wiki at https://gambaswiki.org/ serves as the central documentation hub, offering language references, tutorials, code snippets, and an application repository that catalogs over 70 medium- to large-scale applications and demos written in Gambas. Mailing lists hosted at https://lists.gambas-basic.org/ facilitate discussions, with dedicated lists for general user queries, bug tracker notifications, and Git commit updates. Community-driven sites extend these official channels. The Gambas One forum at https://gambas.one/ acts as the primary English-language for discussions, troubleshooting, and sharing user experiences. The SourceForge project page at https://sourceforge.net/projects/gambas/ hosts downloads, file releases, and a discussion archive, serving as a longstanding for the community. User-contributed resources include tutorials scattered across the and external , such as A Beginner's Guide to Gambas by John W. Rittinghouse, which introduces core concepts for newcomers. Notable projects built with Gambas demonstrate its versatility across domains. Desktop utilities like the BumbleBee Launcher and MV1SysTray provide system integration tools, while educational software such as MyEduBase for student management and Multiple Diploma Builder for certification handling support learning environments. Math tools, including the Azeotrope Chemical Calculator, enable scientific computations. Simple 2D games like Tetris, Checkers, and Tic Tac Toe showcase graphical capabilities. Specific standouts include KediCAD, a CAD application for 2D and 3D design similar to AutoCAD, and Xt7-player-mpv, a GUI frontend for the mpv media player included in various Linux distributions. Contributions to the Gambas project follow a structured process using and . Developers the main at https://gitlab.com/gambas/gambas, implement changes in their branch, and submit merge requests for review, adhering to guidelines for code organization and testing. This workflow ensures external code pieces and artifacts are integrated efficiently. The support ecosystem around Gambas includes third-party libraries and components for specialized needs, though options remain limited compared to more languages. integration is handled through built-in components like gb.web for basic server-side functionality, with community extensions for HTTP handling. Hardware interfacing is supported via gb.serial for serial communication, enabling projects with devices like , as demonstrated in wiki examples for and .

Examples

Simple Script Example

To illustrate the core syntax of Gambas in a non-graphical , consider a basic console script that prompts the user for their name and age, performs string concatenation for a personalized , applies conditional logic to validate the input, and incorporates handling for invalid such as empty name, non-numeric age entries, or out-of-range ages. This example highlights Gambas's interpreted nature, where the script is dynamically compiled to upon execution, enabling without manual compilation steps. The following code defines a complete, standalone saved as greeting.gbs:
gambas
#!/usr/bin/env gbs3

Public Sub Main()

    Try

        Dim sName As String = Input("Enter your name: ")

        If sName = "" Then
            Throw "No name provided."
        End If

        Dim sAge As [String](/page/String) = Input("Enter your age: ")

        If Not IsNumber(sAge) Then
            Throw "Age must be a number."
        End If

        Dim iAge As Integer = Val(sAge)

        If iAge < 0 Or iAge > 150 Then
            Throw "Invalid [age](/page/Age) entered."
        End If

        Print "Hello, " & sName & "! You are " & Str(iAge) & " years old."

    Catch
        Print "Error occurred: " & Error.Text
    End

End
This script begins with a shebang line (#!/usr/bin/env gbs3) to specify the Gambas scripter interpreter, allowing direct execution as a shell script. The Public Sub Main() declares the entry point subroutine, which Gambas automatically invokes when running the script. The Try block initiates protected execution, encompassing the core logic. Dim sName As String = Input("Enter your name: ") declares a string variable sName and assigns it the result of the Input function, which reads a line from standard input after displaying the prompt. The subsequent If sName = "" Then Throw "No name provided." End If uses an If conditional to check for an empty string, raising a custom error with Throw if unmet, demonstrating basic control flow and explicit error raising. Similarly, Dim sAge As String = Input("Enter your age: ") captures the age as a string, followed by If Not IsNumber(sAge) Then Throw "Age must be a number." End If to validate that the input is numeric before conversion. Then, Dim iAge As Integer = Val(sAge) performs the numeric conversion with Val; non-numeric inputs are already caught. The If iAge < 0 Or iAge > 150 Then Throw "Invalid age entered." End If applies another conditional for range validation. If validation passes, Print "Hello, " & sName & "! You are " & Str(iAge) & " years old." outputs the greeting, employing the & operator for string concatenation and Str to convert the integer back to a string for inclusion. The Catch block handles any exceptions raised within Try, accessing the error details via Error.Text and printing them. This structure ensures the script terminates gracefully rather than crashing on errors like non-numeric input. The purpose of this minimal script is to showcase Gambas's interpreted execution model, where the gbs3 command compiles the source to temporary , caches it for reuse, and runs it via the underlying interpreter (gbx3), recompiling only on changes for efficiency. error handling via Try...Catch prevents abrupt halts, promoting robust console applications. To execute, make the file executable with chmod +x greeting.gbs and run ./greeting.gbs, or invoke directly with gbs3 greeting.gbs; for persistent bytecode, convert the script to a full using gbs3 --convert-script and compile via gbc3.

GUI Application Example

A simple yet illustrative GUI application in Gambas is a basic form that allows user input via a text box and displays a dynamic greeting upon button activation, demonstrating core concepts like event handling and control manipulation. This example leverages Gambas' visual form designer and its integration with toolkits such as Qt or GTK+ for cross-platform rendering. To build this application, launch the Gambas IDE and create a new graphical project by selecting "Graphical application" (typically using the Qt backend for broader compatibility). A default main form (FMain) is automatically generated, serving as the primary window. Open the form in the designer view, then access the toolbox (via F6) to drag and drop three controls: a TextBox for input, a Button for interaction, and a Label for output display. Arrange them vertically—place the Label at the top (e.g., at position X=10, Y=10), the TextBox below it (X=10, Y=50, Width=200), and the Button adjacent to the TextBox (X=220, Y=50, Width=80). Set the Button's Text property to "Greet" and ensure the form's Title is "Hello Gambas". These steps utilize the IDE's property editor (F4) for precise control placement and styling without manual coding. Next, implement the logic in the form's class file (FMain.class). In the Form_Open , which triggers when the form loads, initialize the Label's text to user input:
gambas
Public Sub Form_Open()
  Label1.Text = "Enter your name below:"
End
This sets a static message upon startup, showcasing assignment and control properties. For interactivity, double-click the in the to auto-generate the Button1_Click handler. Add the following code to read from the TextBox and update the Label dynamically:
gambas
Public Sub Button1_Click()
  If TextBox1.Text <> "" Then
    Label1.Text = "Hello, " & TextBox1.Text & "! Welcome to Gambas."
  Else
    Label1.Text = "Please enter a name."
  End If
End
This snippet employs conditional logic (If statement) to validate input, concatenation (& operator) for building strings, and property access (e.g., .Text) to link controls. The empty string check prevents blank greetings, highlighting basic error handling. Running the project (F5) launches a windowed application where users type into the TextBox and click the to see the update in . This -driven model—where the button click raises an processed by the handler—exemplifies Gambas' object-oriented approach to development, similar to but extended for environments. The application can be extended by adding features like focus events (e.g., TextBox1_Focus to clear prior input) or persistence via the gb.db component, but this core example establishes foundational workflow for more complex interfaces.