In a previous tip, we showed you how to loop through an array with
the LBound() and UBound() function. The code we provided used these
two functions in the For...Next statement itself, like this:
For x = LBound(MusicGenres) To UBound(MusicGenres)
where MusicGenres was the array we wanted to traverse.
As many astute tipsters pointed out, howevever, when you loop
through large arrays it's much more efficient to set variables to the
LBound() and UBound() function results and use these variables inside
the loop instead. This way, Visual Basic only wastes time performing
the functions once rather than many times.
So the code would then become
lctr = LBound(MusicGenres)
uctr = UBound(MusicGenres)
For x = lctr To uctr
Debug.Print MusicGenres(x)
Next x