411 REFERENCE · Wikibooks
Programming Gambas from Zip/DidYouKnow
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
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
alt=The Form_Open() event handler|frameless|241x241px
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
alt=Code abbreviations|frameless|695x695px
If you want to start writing a new sub, type ps<tab> and you will see already typed for you:Public Sub Name(Arguments)
Endv<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
alt=Automatic Variable Declarations in Gambas|frameless|699x699px
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
alt=Pausing Gambas program execution to look at variables|none|thumb|Breakpoint set on the Dim statement. SoccerPlayer has “Maradona” in it.|595x595px
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
alt=Size and Position Coordinates of Objects on Gambas Forms|frameless|270x270px
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
alt=Commented-out Code, uncommented|left|frame|Uncommented
alt=Commented-out Code, commented|none|thumb|Commented-out|297x297px
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.
Afterword Functions