Getting started in Gambas

Introduction

You've chose to use the very good Gambas programming language! Good choice, very good choice :-) . Gambas is a programming language which is very easy to learn and to use. It is a clear, reliable and simple programming language and, you can do many things with it.

The best way to learn Gambas, is to practice in console to get the mostly of base syntax.

Note, if you are an old user of Visual Basic or QBasic, you must know you won't be lost. Why ? Because Gambas uses a syntax that looks like about VB and QBasic language.

Create a new project

If you have not installed Gambas yet, please do so by going to this page.

The screenshots were took with old development version of Gambas. However, at the moment where i'm typing these lines, the latest stable version of Gambas is the 2.5 ! So, don't worry if some screenshots don't match with your.

Starting by run Gambas2. First of all, a beautiful window opens by asking you what you want to do :

Click on New project. This window will open to every startup of Gambas and will allow you to run quicky what you want.

As you can see, it's relatively simple to create a new project, and you are guided step by step for his create. Here, choose Command line application and click on the Next button.

Here, select your folder where your Gambas project will be saved.

Then, give a name and a title to your project. Applied all by clicking on *OK button.

And here is the result!

Once your project is created, you are into the IDE of Gambas and another beautiful window opens which wishes to you the welcome in Gambas ! In your first step with Gambas, you should prefer to keep this tips window at startup. In this way, you will have more information about Gambas and its particularities as well. You will see the informations gave by that window are helpful :-) .

For the VB users, that tips window allows you to know what are the difference between Gambas and VB.

Your first program in Gambas

If you look at on the left of the IDE, you will see that you've got a module named MMain :

Click twice on it to open the editor. You have a base code like that :

Examples

' Gambas module file

Public Sub Main()

End

This is the main procedure of your program. i.e, it's the first procedure which is executed by the Gambas interpreter. The first of this code is a comment. You can recognize them because there've got a grey color into the editor and begins always by an apostrophe. Comments are useful to indicate informations about source code. For example, to explain what the source code do.

We're going to see how to display something on the screen. To do this, we're going to use the PRINT statement which allows to write on the standard output. The text must be set between quotes:

' Gambas module file

Public Sub Main()

  Print "My first program!"

End

To run the program, press the F5 key or you can run it by Debug -> Start menu, or by the toolbar yet:

A small frame opens at the bottom of the IDE, this is the console. When executing the program, we're getting:

My first program!

To try out in detail the PRINT statement, we're going to add a second PRINT statement:

' Gambas module file

Public Sub Main()

  Print "My first program!"
  Print "Made in Gambas :) !"

End

Congratulation ! You made your first program in Gambas ! :-)

Now, we can go to the following tutorial. It will talk about variables, a point which is very important in programming. - Variables