Skip to main content

Gambas--GAMBAS Almost Means BASIC

Gambas is the name of an object-oriented dialect of the BASIC programming language, as well as the integrated development environment that accompanies it. Designed to run on Linux and other Unix-like computer operating systems, its name is a recursive acronym for Gambas Almost Means Basic.Gambas is also the word for prawns in the Spanish and Portuguese languages, from which the project's logos are derived.
Gambas was developed by the French programmer Benoît Minisini, with its first release coming in 1999. Benoît had grown up with the BASIC language, and decided to make a free software development environment that could quickly and easily make programs with user interfaces.
Ckeck whether Gambus is installed if not enter these commands one by one.
sudo add-apt-repository ppa: shrimp-team / gambas3
sudo apt-get update
sudo apt-get install gambas3

Developing applications in Gambas


Only will take a few minutes to build your first application in Gambas. The graphic user interface (GUI) will be quickly created by drawing on the form widgets like text boxes or command buttons. Then you will set some properties to the form and widgets to specify values like text, color or size. Finally, some code must be written to bring to life your application. Those basic steps that you'll use to create your first application, will show you the principles that you will use for develop any other application in Gambas.
basic steps to create a Gambas application?
a)Create the interface.
b)Set properties.
c)Write code.
1.- Fire up your Gambas IDE, then on the Welcome screen select New project. This opens the New project Wizard.
2.- On screen 1 select QT graphical application.
3.- Select a location to save your project.
4.- Type a name for your project.
Now you can build a sample application
1,2.Creating the Interface and setting the properties
Design GUI using the toolbox and set the properties
Control
Property
Setting
Label1
Text
“Tell me your name:”
Label1
Alignment
Center
Button1
Text
“&Hello”
TextBox1
Text
“Write your name here”
FormMain
Text
“My first Gambas project”
3.Writing the code
The Code editor is where you write the code for your application. The code is a set of language statements, constants & declarations.
To open the Code editor
Double click over the object you want to write code or on the Resources visor select the name of the form or module and from the contextual menu select Edit class.
To create an event procedure
Select the object.
Double click over the object to write the code for the default event. 
Write the code between the statements PUBLIC SUB & END SUB. For this lesson write the following code:
Label1.Text = "Hello " & Textbox1.Text & ". This is my first Gambas project!".
The code for the procedure must be look like this:
PUBLIC SUB Button1_Click()
Label1.Text = "Hello " & Textbox1.Text & ". This is my first Gambas project!"
END SUB
4.Run the application
Click run button or from debug menu choose run or press F5.

Create a new application with three text boxes.First two will read input data and the third textbox will show the result of arithmetic operations when corresponding button is clicked.Place command buttons for each arithmetic operations.
Variables
Introduction
What is a variable? A variable stores an item that can change. e.g. "Car" can be changed to "Cars", 1 can become 567
Variables in programming are indispensable. We can do nothing without variables. So, imagine a program that asks how old a user is. You may wish to print a message depending on the age of the user.
There are many variables types in Gambas, let's start with a few simple ones.
  • Integers - Whole numbers e.g. 1, 14, 897
  • Float - Numbers with decimals e.g. 1.2, 10.115, 0.5, 3.142
  • String - Text e.g. "What is your name?", "Apple"
A variable name must follow some rules:
  • It must never begin by a digit
  • It must never contain any spaces
  • It must never contain any accented character
Let's practice
How to use a variable? Firstly we must declare it, i.e. "create" it before we can use it.In Visual Basic, it was optional unless you enabled the explicit option.
In Gambas, you must declare all your variables. This is good practice and will help avoid making some mistakes.
This is one way to declare a variable:
Dim MyAge As Integer
You can assign a value like this:
Dim MyAge As Integer = 25
Dim nickname As String
nickname = "NewToGambas" 'This is another way to assign a value
Let's have a look at how to print a variable by using the PRINT command:
' Gambas module file
Public Sub Form_Open()
  Dim nickname As String = "NewToGambas"
  Print "My nickname on internet is " & nickname
End
To concatenate (join together) any String variables, we use the & operator.
It's easy, isn't it?
Work with information from the user
To get some data from the user, we will use the InputBox command.  Here is an example:
' Gambas module file
Public Sub Form_Open()
  Dim nickname As String
  nickname = InputBox("What is your nickname?")
  Print "Your nickname is " & nickname
End
When the program arrives at this line:
nickname = InputBox("What is your nickname?")
It will stop and wait for the data from user and continue when the user presses the Return (or Enter) key.
Test control and loop structures
Without these structures, our programs would work in a sequential way, and would be very poor.

Test structures

This allows us to perform some instructions if a condition is true.

If ... Then

This is the structure the most basic:
If condition Then

Endif
condition is the expression to test. The condition signs are:
  • > : purely upper
  • < : purely lower
  • >= : upper or equal
  • <= : lower or equal
  • = : equal
  • <> : unlike
Thus we can compare two values, two variables for example:
If Variable1 = Variable2 Then
Here, the "=" sign indicates an equality test, and not a value being assigned to a variable (like in a = 1).
Now, Here is an example to show that:
Public Sub Main()
  Dim age As Integer
  Print "How old are you? "
  Input age

  If age >= 18 Then
    Print "You are major."
  Else
    Print "You are minor."
  Endif
End
The ELSE keyword is optional. Example:
' Gambas module file

Public Sub Main()
  Dim power As Integer = 15  'power in ch
  If puissance < 15 Then
    Print "Do you want to change your car? :p "
  Endif
End
Another note, the ENDIF keyword is optional if there is only one instruction to execute:
Public Sub Main()
  Dim power As Integer = 15  'power in ch

  If puissance < 15 Then Print "Do you want to change your car? :p "
End

The Select ... Case structure

We're using this structure when there are many values to test. With this structure, our code is more clear to read:
Public Sub Main()

  Dim pays As string

  Print "De quel pays venez-vous ?"
  Input pays
  pays= lcase(pays) 'remove uppercase

  Select Case pays
     Case "france"
        Print "Bonjour !"
     Case "england"
        Print "Hello!"
     Case "espana"
        Print "Ola!"
     Case "portugal"
        Print "Hola !"
     Case Else
        print"??"
  End Select
End
Loops
Loops allows you to repeat one or more instructions. Three loops type exists allowing you to do the same thing in a different way.
For
The For loop allows to repeat an instructions block n times.
Public Sub Main()
  Dim i As Integer
  For i = 1 To 5
    Print "Value of i: " & i
  Next
End
When Gambas enters the loop for the first time, it applies the value 1 to i, then executes next instructions until it meets the NEXT keyword. Gambas returns to the beginning of loop, then increments the i variable until it reaches 5. The loop instructions will be read 5 times:
Value of i: 1
Value of i: 2
Value of i: 3
Value of i: 4
Value of i: 5

Do ... Loop

Sometimes we don't know the number of loops to do. But we know how it must stop. Here is an example:
Public Sub Main()
  Dim result As integer
  Print "How many two and two?"
  Do
     Input result
  Loop Until result = 4
  PRINT "Congratulation! You have found :-) "
End
We can also use the WHILE keyword instead of UNTIL to make a loop structure with a condition.
Do Input result Loop While result <> 4
While
About WHILE, there is a loop structure specially for While:
' Gambas module file
Public sub Main()
  Dim age As Integer
  While age < 10
    Inc age
    Print "Value of age : " & age
  Wend
End
Result:
Value of age : 1
Value of age : 2
Value of age : 3
Value of age : 4
Value of age : 5
Value of age : 6
Value of age : 7
Value of age : 8
Value of age : 9
Value of age : 10

Comments

Popular posts from this blog

Linux History and GNU

Linus Torvalds ,a student at the University of Helsinki started developing Linux to create a system similar to MINIX, a UNIX operating system. In 1991 he released version 0.02; Version 1.0 of the Linux kernel, the core of the operating system, was released in 1994. About the same time, American software developer Richard Stallman and the FSF made efforts to create an open-source UNIX-like operating system called GNU. In contrast to Torvalds, Stallman and the FSF started by creating utilities for the operating system first. These utilities were then added to the Linux kernel to create a complete system called GNU/Linux, or, less precisely, just Linux. Linus Torvalds Richard Stallman Linux grew throughout the 1990s because of the efforts of hobbyist developers. Although Linux is not as user-friendly as the popular Microsoft Windows and Mac OS operating systems, it is an efficient and reliable system that rarely crashes. Combined with Apache, an open-source Web server, Linux accounts fo

Introduction to Data Structures

Visit My Data Structure Blog for Programs... It is important for every Computer Science student to understand the concept of Information and how it is organized or how it can be utilized. If we arrange some data in an appropriate sequence, then it forms a Structure and gives us a meaning. This meaning is called Information . A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently. Data may be organized in many different ways. The logical model of a particular organization of data in a computer is called data structure. The choice of the model based on two considerations. It should be reflect the data in the real world. It should be simple that one can effectively process the data when necessary. E.g. Array, linked list, stack, queue, tree, graph Data structure can be classified into two: Linear: A data structure is said to be linear if its elements form a sequence E.g. Array, linked list, stack, queue Non-Linear: A dat

Basic Linux Commands For Beginner's

Basic Linux Commands for Beginners Linux is an Operating System’s Kernel. You might have heard of UNIX. Well, Linux is a UNIX clone. But it was actually created by Linus Torvalds from Scratch. Linux is free and open-source, that means that you can simply change anything in Linux and redistribute it in your own name! There are several Linux Distributions, commonly called “distros”. A few of them are: Mint Ubuntu Linux Red Hat Enterprise Linux Debian Fedora Kali Linux is Mainly used in Servers. About 90% of the Internet is powered by Linux Servers. This is because Linux is fast, secure, and free! The main problem of using Windows Servers are their cost. This is solved by using Linux Servers. Forgot to mention, the OS that runs in about 80% of the Smartphones in the World, Android, is also made from the Linux Kernel. Yes, Linux is amazing! A simple example of its security is that most of the viruses in the world run on Windows, but not on Linux