<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../style.css">
<title>
Gambas Documentation - Array Declaration
</title>
</head>
<table class="none" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr><td align="left">
<font size="-1">
<a href="../../help+en"><img class="flag" alt="Home" border="0" src="../../img/lang/en.png" align="center"></a>&nbsp;
<a href="../cat+en">Up</a>&nbsp;
<a href="array+en">Previous</a>&nbsp;
<a href="assign+en">Next</a>&nbsp;
</td></tr></table>
<div class="notab">
<h1>
Array Declaration
</h1>
<div class="black"><font size="-2"><b>Syntax</b></font></div>
<pre class="syntax"><b>DIM</b> <u>Identifier</u> <b>AS</b> [ <b>NEW</b> ] <u>Native Datatype</u> <b>[</b> <u>Array dimensions</u> ... <b>]</b></pre><p>

Note that you can use any expression for specifying array dimensions.
<p>
<div class="gray"><font size="-2"><b>Example</b></font></div>
<pre class="example">DIM aWords AS NEW String[WORD_MAX * 2]
DIM aMatrix AS NEW Float[3, 3]</pre>
<p>
<h2>Dimensions</h2>
<p>
The variables can have dimensions, <a href="../lang/type/integer+en">Integer</a> variables may have a maximum of 8 dimensions.
<p>
<div class="gray"><font size="-2"><b>Example</b></font></div>
<pre class="example">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]
DIM fX9X AS NEW Float[3, 4, 5, 2, 3, 2, 2, 4, 2]</pre>
<p>
The name &quot;<a href="../lang/dim+en">DIM</a>&quot; for this declaration comes from the sixties, where BASIC variables did not need to be declared, except variables with dimensions.
<p>
<div class="warning"><table class="none" border="0"><tr><td width="40" valign="top"><img border="0" src="../../img/vb.png" align="center"></td><td valign="top">
<a href="../def/gambas+en">Gambas</a> uses brackets [ ] instead braces ( ) to declare and use dimensions.
</td></tr></table></div>
<p>
<h2>Static arrays</h2>
<p>
<div class="black"><font size="-2"><b>Syntax</b></font></div>
<pre class="syntax">[ <b>STATIC</b> ] { <b>PUBLIC</b> | <b>PRIVATE</b> } <u>Identifier</u> <b>[</b> <u>Array dimensions</u> ... <b>]</b> <b>AS</b> <u>Native Datatype</u></pre><p>

A <a href="../def/staticarray+en">static array</a> is an array that is allocated directly inside the
<a href="../def/object+en">object</a> where it is declared.
<p>
Such an array cannot be shared, and is destroyed with the <a href="../def/object+en">object</a>.
<p>
A static array cannot be public, and you cannot initialize it.
<p>
<div class="warning"><table class="none" border="0"><tr><td width="40" valign="top"><img border="0" src="../../img/warning.png" align="center"></td><td valign="top">
Do not use static arrays as local variables. It works at the moment, but may be removed in the future.
</td></tr></table></div>
<p>
<div class="gray"><font size="-2"><b>Example</b></font></div>
<pre class="example">PRIVATE Handles[8] AS Label
STATIC PRIVATE TicTacToe[3, 3] AS Integer</pre>
<p>
<hr><b>See also</b><br>
<a href="../lang/vardecl+en">Variable Declaration</a>&nbsp; <a href="../lang/localdecl+en">Local Variable Declaration</a>&nbsp;

</div>
</body>
</html>

