< Programming Gambas from Zip

Did You Know? — From Gambas ONE

Shortcuts in Writing Code

Thanks to cogier, stevedee and jornmo on Gambas One. https://forum.Gambas.one/viewtopic.php?f=4&t=489

The Form_Open() event handler

Double-click a blank area of the form to start typing code for the Public Sub Form_Open() event. Double-click a button to start typing code for Public Sub Button_Click(). Otherwise, right-click the object or form > click EVENT… > choose the event you want to write code for.

Expansions

Code abbreviations

If you want to start writing a new sub, type ps<tab> and you will see already typed for you:

Public Sub Name(Arguments)

End

v<tab> is changed into Private $Var As Type

ds<tab>, df<tab> and di<tab> are changed into

Dim sVar As String

Dim fVar As Float

Dim iVar As Integer

Help

If you hold down the CTRL key and click on a Gambas reserved word (e.g. Public, New, For, etc) the relevant help page is displayed. Selecting a keyword and pressing F2 also does it.

Right-click a tool in the toolbox and help will appear.

Declaring Variables

Automatic Variable Declarations in Gambas

In preferences (Ctrl-Alt-P) switch on Local variable declaration then in your empty 'Sub' type iCount = 6 and a Dim iCount as Integer automatically appears.

Pausing and Looking at Variables

Pausing Gambas program execution to look at variables
Breakpoint set on the Dim statement. SoccerPlayer has “Maradona” in it.

If the program is paused (you put in a “breakpoint” in a certain place in the code, and the execution reached this place, or you click the Pause button) you can select a variable (drag over it, or double-click it) and you will see its value.

Widen, Shorten and Move Things

Size and Position Coordinates of Objects on Gambas Forms


If you select the width or height properties of a control, the up or down arrows increase or reduce it by 7 pixels.

If you select the X property of a control, up-arrow moves right, down-arrow moves left by 7 pixels. Similarly in the Y property value box, up-arrow moves down and down-arrow moves up (work that one out) by 7 pixels.

If you want a line or selected lines of code to move up, click in the line and press Alt-UpArrow. Alt-DownArrow moves it or them down.

Many Random Numbers

Dim siRand1, siRand2, siRand3, siRand4 As Short = Rand(0, 9)

This declares four short integer variables and puts a random digit between 0 and 9 into each.

Deleting a Whole Line of Code

Press Shift-Delete anywhere on the line.

Commenting and Uncommenting Lines of Code

Commented-out Code, uncommented
Uncommented
Commented-out Code, commented
Commented-out


Select the lines > Press Ctrl-K to “komment-out” the lines. Ctrl-U with lines selected will un-comment them. (Commenting out means making them into comments so they are not executed.)

Non-Case-Sensitive Comparisons

Use a double equals sign to disregard case. For example, "Hello" == "HELLO" is true. "Hello" = "HELLO" is false.

You can also use a function to compare two strings String.Comp("Hello", "HELLO", gb.IgnoreCase) = 0 . String.Comp("Hello", "HELLO") <> 0 is true.

This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.