In the Gambas language, the assignment operator is the equals sign =. The syntax for an assignment operation can generally be described by Target = Expression. The value of Expression can be assigned to one of the following targets:
|Target == Printout||Direct, simple assignment|
Table 8.1.1: Assignment operator
The assignment operation is subject to legal associativity. This means that the printout on the right-hand side is evaluated first and then assigned to the target on the left-hand side.
Please note that the equal sign bivalent is also used as a comparison operator in the following sections of chapter 8.
The complex or composite assignment operators represent only abbreviated forms of assignments with special operators in the expression:
|Complex assignment operator||Description|
|Target += Expression||Synonym for the assignment: Target = Target + Expression|
|Target -= Expression||Synonym for the assignment: Target = Target - Expression|
|Target ? = Expression||Synonym for the assignment: Target = Target? Expression|
|Target /= Expression||Synonym for the assignment: Target = Target / Expression|
|Target \= Expression||Synonym for the assignment: Target = Target DIV Expression|
|Target %= Expression||Synonym for the assignment: Target = Target MOD Expression|
|Target &= Expression||Synonym for the assignment with the operator & to connect strings: Target = Destination & Expression|
|Target &/= Expression||Synonym for the assignment with the operator & to connect strings for paths: Target = Target &/ Expression|
Table 220.127.116.11: Complex assignment operators
 Dim fNumber As Float   fNumber = 9.55  fNumber += 2 * (-3.21) ^ 3 ' Error: Print fNumber += 2*(-3.21)^3  ' fNumber = fNumber + 2 * (-3.21) ^ 3  Print fNumber
 PUBLIC CONST DefaultStartX AS Float = -5.0  Private aMatrix As Variant  aMatrix = New Variant  Dim aNames As String = ["Hans", "Maria", "Peter", "Anna", "Robert"]  TableView1.Sorted = NOT TableView1.Sorted  TableView1.Columns.Count = 4  TableView1.Header = TableView1.Both  TableView1.Mode = Select.Single  Me.Flags[Editor.ShowLimits] = (iLimit > 0) AND (iLimit < 3)  btnTableViewExportCSV.Enabled = True  If Row MOD 2 = 0 Then TableView1.Data.Background = Color.RGB(224, 224, 224) ' hellgrau
Please note: In line 11, the first equals sign = is a comparison operator, while the second equals sign = an assignment operator. The background color of the component TableView (target) is set to light grey (value of expression).
Some statements that return values such as SWAP, EXEC, SHELL, OPEN, NEW, RETURN, or RAISE often also use the assignment syntax, as the following examples show:
IF Printer.Portrait = TRUE THEN SWAP MargeB, MargeL SWAP aIndexField[iRow].Field, aIndexField[iRow - 1].Field SWAP iForeground, iBackground
SHELL and EXEC:
hWhichAsProcess = EXEC ["which", "gnuplot"] Wait For Read hGnuPlot = SHELL "gnuplot" For Read Write As "hGnuplot"
hDatei = OPEN (User.Home &/ "V24T" &/ "v24T.conf") FOR CREATE hFile = OPEN sDTDDateiPfad FOR CREATE ' DTD file is newly created or emptied fFile = OPEN Dialog.Path FOR READ ' Open data file for reading TRY fFile = OPEN Dialog.Path FOR WRITE ' Open data file for writing
$EditGrid = NEW TextBox(hParent) AS "EditGrid" MyParentObserver = NEW Observer(Me.Parent) As "Parent" IF NOT $cSlot.Exist(sSlot) THEN $cSlot[sSlot] = NEW Collection hMenuItem = NEW Menu(hContext) As "mnuFileOpen"
RETURN - Return of a function value
RETURN (Value - Me.MinValue) / (Me.MaxValue - Me.MinValue) RETURN Potentiometer.Spin IF hCtrl.Window.TopLevel THEN RETURN Object.Type(hCtrl.Window) RETURN Sin(x) * Cos(x / 0.56) + (Pi / 3) RETURN FALSE
' Gambas class file ' © 2008 Daniel Fuchs EXPORT CREATE PRIVATE INHERITS UserControl ' The following events are already contained in the UserControl class: EVENT Activate EVENT MouseWheel() AS Boolean ... PUBLIC SUB DrawingArea_MouseWheel() DIM Cancelled AS Boolean MySlideTimer.Stop Cancelled = RAISE MouseWheel() IF Cancelled OR NOT ME.Enabled THEN RETURN ME.Value = (ME.Value - Mouse.Delta * ME.GetSpin() * ME.PageStep) RAISE Activate END ' DrawingArea_MouseWheel()