<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<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>
<body>
<table class="none" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr><td align="left">
<font size="-1">
<a href="../../help%3Fen"><img class="flag" alt="Home" border="0" src="../../img/lang/en.png" align="center"></a>&nbsp;&nbsp;
<a href="../lang%3Fen">Up</a>&nbsp;&nbsp;
<a href="array%3Fen">Previous</a>&nbsp;&nbsp;
<a href="as%3Fen">Next</a>&nbsp;&nbsp;
</td></tr></table>
<div class="notab">
<h1>
Array Declaration
</h1>
<div class="black"><font color="white" size="-2"><b>Syntax</b></font></div>
<pre class="syntax"><b>DIM</b> <u>Identifier</u> <b>AS 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 color="white" 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="type/integer%3Fen">Integer</a> variables may have a maximum of 8 dimensions.
<p>
<div class="gray"><font color="white" 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="dim%3Fen">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%3Fen">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 color="white" 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%3Fen">static array</a> is an array that is allocated directly inside the
<a href="../def/object%3Fen">object</a> where it is declared.
<p>
Such an array cannot be shared, and is destroyed with the <a href="../def/object%3Fen">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 moement, but may be removed in the future.
</td></tr></table></div>
<p>
<div class="gray"><font color="white" 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="vardecl%3Fen">Variable Declaration</a>&nbsp;&nbsp; <a href="localdecl%3Fen">Local Variable Declaration</a>&nbsp;&nbsp;

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

