Array Declaration Questions

chuckjitsu

New Member
Joined
Apr 24, 2015
Messages
48
Office Version
  1. 365
  2. 2016
Let's say you see code like this:
VBA Code:
Dim myArray (1 to 5) as Byte

I'm assuming this means that by declaring the array as the byte data type, all the data elements in the array are of the declared variety (0 to 255)? Is that correct?

Now, let's say you had another array you were using to store myArray- an array of arrays if you will. We'll call this the second array myArray2. Can myArray2 be declared as something other than the Variant type? What are the declaration rules for an array that stores other arrays?

Thanks!
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Yes, you are correct. When you declare an array of type Byte, it means that each element of the array will hold a value in the range of 0 to 255.

Regarding the second array (myArray2), it can indeed be declared as a different data type other than Variant, as long as it is capable of storing the values of the first array (myArray).

In VBA, you can declare the second array as an array of arrays, by using nested square brackets []. For example:

Dim myArray2 (1 to 5, 1 to 5) as Byte

This declares myArray2 as a two-dimensional array, with 5 elements in each of the 5 dimensions.

Keep in mind that each element of the inner array (myArray) must have the same data type, in this case, Byte, so that the values of myArray can be stored in myArray2.
 
Upvote 0
Solution

Forum statistics

Threads
1,224,592
Messages
6,179,777
Members
452,942
Latest member
VijayNewtoExcel

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top