Page 1 of 1
is there a maximum size for a 2D array?
Posted: Sun May 06, 2007 2:44 am
by carrie
I am getting a 'subscript out of range' error when I try to create a 2D array with more than 179x179 elements. What's happening? Is there a workaround? Thanks, Carrie
Posted: Sun May 06, 2007 9:35 pm
by Ralph
Carrie, a "Subscript out of range" error message appears when you use an array element that is beyond the available limit for the particular variable you are using. For integers, that means that, if you are using
DIM A(J,J) AS INTEGER
for your array, A, you are limiting your array to a number of elements equal to or less than the maximum INTEGER number allowed, which is 2^15-1 = 32,767 = 181*181, so the maximum value of J you can use there is the 180, if you are using A(0,0) as a valid array, since 181*181 = 32,761.
BUT...if you use a LONG number, thus,
DIM A(J,J) AS LONG
since the largest LONG integer number is 2^31-1 = 2,147,483,647, whose square root is 46,340.65, the largest value of J you can now use is 46,339. How about that?