is there a maximum size for a 2D array?

Please use this Board for QBasic related requests ( file research, programming, etc.)

Moderators:Administrator, Global Moderator

Post Reply
carrie
Newbie
Posts:1
Joined:Sun May 06, 2007 2:41 am
is there a maximum size for a 2D array?

Post by carrie » Sun May 06, 2007 2:44 am

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

Ralph
QBasic God
Posts:134
Joined:Sat Nov 06, 2004 2:27 am
Location:Katy, Texas

Post by Ralph » Sun May 06, 2007 9:35 pm

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?
Ralph. Running QuickBASIC Version 4.5, Windows XP Home Edition, Version 2002, Service Pack 2, and HP LaserJet 4L printer.

Post Reply