Gambas Documentation
Application Repository
Code Snippets
Compilation & Installation
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

Array Declaration

DIM Identifier AS [ NEW ] Datatype [ Array dimensions ... ]

Note that you can use any expression for specifying array dimensions.

Examples

Dim aWords As New String[WORD_MAX * 2]
Dim aMatrix As New Float[3, 3]
Dim aResult As String[]

In Gambas 3, any datatype can be used as array element.

Examples

Dim aLabel As New Label[12, 12]
Dim aResult As New String[][12] ' An array of string arrays!

Dimensions

The array can have several dimensions, up to a maxium of eight.

Examples

Dim iGroupc As New Integer[27, 9]
Dim iFieldr As New Integer[9]
Dim iX9X As New Integer[3, 4, 5, 2, 3, 2, 2, 4, 2] 'will report error

The name "DIM" for this declaration comes from the sixties, where BASIC variables did not need to be declared, except variables with dimensions.

Gambas uses brackets [ ] instead of braces ( ) to declare and use dimensions.

Embedded arrays

[ STATIC ] { PUBLIC | PRIVATE } Identifier [ Array dimensions ... ] AS Native Datatype

An embedded array is an array that is allocated directly inside the object where it is declared.

Such an array cannot be shared, and is destroyed with the object.

An embedded array cannot be public, and you cannot initialize it.

Embedded arrays were created to ease the interface between Gambas and external functions located in shared libraries.

Consequently, I strongly suggest to use them only if you cannot use normal arrays.

Or if your code run faster with embedded arrays than with normal arrays, as it's possible in some cases.

In Gambas 3, embedded arrays cannot be used as local variables anymore. But they can be public!

Since 3.17

Embedded array dimensions can be defined with constant expressions.

Examples

Private Handles[8] As Label
Static Private TicTacToe[3, 3] As Integer

See also