-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path570.html
More file actions
86 lines (82 loc) · 2.52 KB
/
Copy path570.html
File metadata and controls
86 lines (82 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<h1 id="dim">DIM</h1>
<blockquote>
<p>DIM var([lower TO] upper [, …]) [, …]</p>
</blockquote>
<p>Reserves storage space for an array.</p>
<p>The array will have (upper-lower)+1 elements. If <code>lower</code>
is not specified, and <code>OPTION BASE</code> hasn’t used, elements
start at 0.</p>
<h2 id="example-1-one-dimensional-arrays">Example 1: One dimensional
arrays</h2>
<pre><code>REM One dimensional array of 7 elements, starting from 0
REM with elements A(0), A(1), ... , A(6)
DIM A(6)</code></pre>
<pre><code>REM One dimensional array of 7 elements, starting from 3
REM with elements A(3), A(4), ... , A(9)
DIM A(3 TO 9)</code></pre>
<pre><code>REM One dimensional array of 6 elements, starting from 1
REM with elements A(1), A(2), ... , A(6)
option base 1
DIM A(6)</code></pre>
<h2 id="example-2-multi-dimensional-arrays">Example 2: Multi dimensional
arrays</h2>
<pre><code>REM Two dimensional array
DIM A(3, 4)</code></pre>
<pre><code>REM Three dimensional array
DIM A(2 TO 6, 5 TO 9, 1 TO 8)</code></pre>
<h2 id="example-3-empty-array">Example 3: Empty array</h2>
<pre><code>REM Allocating zero-length arrays:
DIM z()</code></pre>
<h2 id="example-4-creating-and-accessing-arrays">Example 4: Creating and
accessing arrays</h2>
<pre><code>
Option Base 1 ' Set default lower bound of arrays to 1
? "Showing x,y,z elements of index 5:"
?
' Reserve space for a single 1-dimensional array:
x = 0
y = 10
z = 20
Dim a(1 To 30)
For i = 1 To 10
a(i + x) = i
a(i + y) = i + 10
a(i + z) = i + 100
Next
? a(5 + x), a(5 + y), a(5 + z),, "(1-dimensional array)"
' Reserve the same space for three 1-dimensional arrays:
Dim a_x(1 To 10), a_y(1 To 10), a_z(1 To 10)
For i = 1 To 10
a_x(i) = i
a_y(i) = i + 10
a_z(i) = i + 100
Next
? a_x(5), a_y(5), a_z(5),, "(three 1-dimensional arrays)"
' Reserve the same space for a single 2-dimensional array:
x = 1
y = 2
z = 3
Dim a(1 To 10, x To z)
For i = 1 To 10
a(i, x) = i
a(i, y) = i + 10
a(i, z) = i + 100
Next
? a(5, x), a(5, y), a(5, z),, "(2-dimensional array)"
' Reserve the same space for a single nested array:
Dim a(1 To 10)
For i = 1 To 10
a(i) = [,,] ' convert this element to nested array
a(i)(x) = i
a(i)(y) = i + 10
a(i)(z) = i + 100
Next
? a(5)(x), a(5)(y), a(5)(z),, "(nested array)"
' Reserve the same space for a single map array (see also: ARRAY, ISMAP):
Dim a(1 To 10)
For i = 1 To 10
a(i).x = i
a(i).y = i + 10
a(i).z = i + 100
Next
? a(5).x, a(5).y, a(5).z,, "(map array)"</code></pre>