Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read declaring an array size?

Tags:

excel

vba

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)
like image 432
Samuel Balun Avatar asked Apr 29 '26 06:04

Samuel Balun


1 Answers

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.

like image 161
Scott Craner Avatar answered May 02 '26 21:05

Scott Craner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!