<!-- PDF page 70 -->

### DIM function

Apart from the **DIM** array declaration command, there's also a function by the same name that returns information regarding any declared array. It's syntax is:

**DIM** (*arrayname[$]()* [, *dimension*]) |*numeric* and it returns the number of elements in the specified *dimension* of the array *arrayname* (dimension defaults to **0** if not specified).

If *dimension* equals **0**, **DIM** will simply return the number of dimensions in the array.

Simple strings are treated as single-dimension character arrays, returning **1** as the number of dimensions and the current string length as the number of elements in dimension **1**.\
Let's write a little program to illustrate:

```
10 DIM a(100,10,5)
20 PRINT DIM (a())
30 PRINT DIM(a(),1)
40 PRINT DIM(a(),2)
50 PRINT DIM(a(),3)
```

which will return:

```
  3
100
 10
  5
```

### Exercises

1. Use **READ** and **DATA** statements to set up an array **m$** of twelve strings in which **m$(n)** is the name of the *nᵗʰ* month. (Hint: the **DIM** statement will be **DIM m$(12,9)**. Test it by printing out all the **m$(n)** (use a loop)).

2. Type:

   ```
   PRINT "now is the month of
   ";m$(5);"ing"; " when
   merry lads
   are playing"
   ```

   What can you do about all those spaces?

