Gambas Documentation
Application Repository
Code Snippets
Compilation & Installation from source code
Components
Controls pictures
Deprecated components
Developer Documentation
Development Environment Documentation
Documents
Error Messages
Gambas Playground
How To's
Language Index
Language Overviews
Arithmetical Functions
Arithmetic Operators
Array Declaration
Assignment Operators
Assignments
Binary Data Representation
Bits Manipulation Functions
Character Test Functions
Comparison methods
Complex numbers
Constant Declaration
Constant Expression
Conversion Functions
Datatype Functions
Datatypes
Date & Time Functions
Enumeration declaration
Error Management
Event Loop
Event Management
Events declaration
Expressions
External Function Management
File & Directory Functions
File & Directory Paths
File mode syntax
Floating Point Numbers
Formatting functions
Gambas Object Model
Global Special Event Handlers
Integer numbers
Intrinsic Functions
Language Constants
Localization and Translation Functions
Local Variable Declaration
Logarithms & Exponentials Functions
Logical Operators
Loop Control Structures
Method Declaration
Miscellaneous Control Structures
Miscellaneous Functions
Native Arrays
Native Container Classes
Object & Class Management
Operator Evaluation Order
Predefined Constants
Process Management
Property Declaration
Random Numbers Functions
Special Methods
Stream & Input/Output functions
String Functions
String Operators
Structure declaration
Test Control Structures & Functions
Trigonometric Functions
User-defined formats
Using reserved keywords as identifiers
Variable Declaration
Last Changes
Lexicon
README
Search the wiki
To Do
Topics
Tutorials
Wiki License
Wiki Manual

Assignments

[ LET ] Destination = Expression

Assigns the value of an expression to one of the following elements:
  • A local variable.

  • A function parameter.

  • A global or a class variable.

  • An array slot.

  • An object public variable.

  • An object property.

This cannot be used to set the value returned by a function. To assign the value of a function, use the RETURN statement.

Some instructions that return something may use the assignment syntax as well: EXEC, NEW, OPEN, RAISE, SHELL.

Examples

iVal = 1972
Name = "Gambas"
hObject.Property = iVal
cCollection[sKey] = Name
...

Assignments of embedded structures or arrays

Since 3.17

If the assignment Destination is actually a structure or an embedded array, then the contents of Expression is recursively copied in the Destination.

Of course, Expression is first converted to the datatype of Destination before the copy is done.

When an array is copied, if the source and the destination do not have the same number of elements, then the smallest number of elements is used to do the copy.

The copy is done only when the structure or the array are embedded. If not embedded, then structures and arrays are normal Gambas objects, and the assignment is just a reference copy.

Examples

Struct Person
  FirstName As String
  LastName As String
  Age As Integer
  BirthDate As Date
  Height As Float
End Struct

Private $aPeople[16] As Struct Person
Private $hFirst As Struct Person
Private $aOther[4] As Struct Person

...

' Copy the 4th people into $hFirst
$hFirst = $aPeople[3]
' Copy the four first people into $aOther
$aOther = $aPeople
' Only the four first elements of $aPeople are modified
$aPeople = $aOther

See also