Gambas/Hello World

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Every programming book should start out with a "Hello World" program, just to get you started. This book's author sees no reason not to follow this "standard" so we will do just that.

Create a new project[edit | edit source]

Start gambas You will be greeted with this screen:


After that follow the steps as described below(no screen-shots)
Click "New Project":
Click "Next":
Select "Create a graphical project":
Click "Next":
In the "Select the name of the project" insert Hello_World
In the "Select the title of the project" insert Hello World
Click "Ok" to create the project

Create the Form(Window)[edit | edit source]

Ok, now we should have gambas started with a fresh, new project. You are now looking at the Gambas GUI, which is where we will do all our Gambas work. When you look at the interface, it seems pretty useless; No windows, No buttons or what have you. Let's change that right away.

On your left side, you'll see a tree view, right click on the Forms folder, and choose "New --> Form"(the --> indicates that you choose New, and follow the submenu to Form).

In the Create form dialog, just click "Ok".

As you noticed, quite a few things happened. A new Form (Window) was created, and some other new things showed up. NOTE: In gambas a Window is called a Form. I will use the term Form(s) in the rest of the book.

The grey Form that just got created looks a bit ugly(tiny dots all over the place) but don't worry about that. The dots are there for your aid in placing your objects in the Form.

To your right you should see the "ToolBox". That's where you can choose what objects you want in your form. In our "Hello World" program, we'll need one label(marked as "A" in the toolbox) and one button(marked as "Ok" in the toolbox). Let's start with the label. Click on the label in the toolbox, and move the new form. In the form, hold down the left mouse button, and "draw" the label on there. Once done, you will have a label in your form with the text "Label1" in it. Now you can change this text with the "Hello Word" phrase.

The next step is to put some code in the Ok Button (you must change the text to "OK" of this button as you changed in the Label). After changing the text please double click the button so we can enter the exit code in the event click of this button. Type QUIT in the click event and that's all you've created your Hello World Application

index