Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming array dimensions in Excel VBA

Tags:

excel

vba

I'm working with threedimensional arrays and it would be neat if I could name the array dimensions. The question marks in the example below are giving me the idea that this is possible.

Is it, and if so, how does it work? I can't seem to find it anywhere.

Example

like image 248
Grafit Avatar asked Oct 18 '22 18:10

Grafit


1 Answers

The three question marks are showing you that this array has three dimensions. If there was only one question mark, it would mean that the variable was declared as one dimensional. This is built in to VB and can't be change, as far as I know.

I think there's real value into making your code more readable and self-documenting. If I had a three dim array, I would probably create some custom class modules to model the objects that I was using.

If your first dimension is a SchoolID, your second dimension is a ClassID, and your third dimension is a StudentID, then code using custom class modules like this

Debug.Print Schools(10).Classes(3).Students(7).Name

is more readable than

Debug.Print arrLeeftijdenG5(10,3,7)

I don't know what you're storing, so it's just an example. Consider using custom class module to model the real-world objects your code is manipulating. There's a bit more set up involved, but it pays dividends down the road.

like image 163
Dick Kusleika Avatar answered Oct 22 '22 01:10

Dick Kusleika