Microsoft KB Archive/75517

= REDIM PRESERVE Only Allows Changing Rightmost Subscript =

Article ID: 75517

Article Last Modified on 8/16/2005

-

APPLIES TO


 * Microsoft Visual Basic for MS-DOS
 * Microsoft BASIC Professional Development System 7.1

-



This article was previously published under Q75517



SUMMARY
When using the REDIM PRESERVE statement to redimension a multidimensional array in Microsoft Visual Basic for MS-DOS, version 1.0; or Microsoft Basic Professional Development System (PDS) for MS-DOS, version 7.1, you are only allowed to change the value of the last subscript (or the value of the first subscript if you invoke BC.EXE with the /R option), or you will get the error message &quot;Subscript Out Of Range&quot;.



MORE INFORMATION
The REDIM PRESERVE statement lets you change the dimensions of an array in memory. Because the default in Basic is to store arrays in column major order, changing any dimension other than the rightmost subscript in a multidimensional array results in a restructuring of that array. Because the REDIM PRESERVE simply truncates the array in memory or extends it if a greater dimension is used, a physical restructuring of the array is not possible. Arrays are stored in memory as follows: |0,0| |1,0| |2,0| |0,1| |1,1| |2,1| and so on.... ---  ---   ---   ---   ---   --- In the above example, changing the left subscript will result in a reordering of the array, whereas changing the right subscript will add or delete new data to the end of the array.

You can change the leftmost subscript of the array only if you compile your program with the BC /R option, which makes Basic store all its arrays in row major order. Note that with Basic PDS for MS-DOS, version 7.1, you can compile with BC /R and /ZI (for CodeView information) if you want to debug a row major program in the CodeView debugger CV.EXE (as a substitute for the QBX.EXE debugging environment).

Note that the /R switch cannot be used within VBDOS.EXE or QBX.EXE; therefore, VBDOS.EXE or QBX.EXE can only store arrays in column major order.

Additional query words: VBmsdos 1.00 7.10

Keywords: KB75517

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.