Samuel Balun
Samuel Balun

Reputation: 79

How to read declaring an array size?

I've got an array declaration which results in 144 slots. I don't understand how I've got to this number. Also, what means all those commas between numbers?

Dim arr4(1, 5, 5, 0 To 1) As Long
    Debug.Print ArraySize(arr4)

Upvotes: 3

Views: 72

Answers (1)

Scott Craner
Scott Craner

Reputation: 152660

The , denotes a new dimension. So arr4 has 4 dimensions.

When using 0 to 1 it is saying that the fourth dimension has two, 0 and 1

When using just one number 5 then the starting point is assumed 0 unless changed in the settings, so there are 6 in that dimension: 0,1,2,3,4,5

The reason there are 144 is because 2*6*6*2=144

Think of it this way.

1st dimension is rows with two row (0,1)
2nd dimension is columns with 6 columns (0,1,2,3,4,5)
3rd dimension create 6 sheets of the above configuration (0,1,2,3,4,5)
4th dimension create 2 workbooks with each having 6 sheets with 12 cells (0,1)

Thus there is 144 cells in which to put data.

Upvotes: 10

Related Questions