REDIM PRESERVE Only Allows Changing Rightmost Subscript (75517)



The information in this article applies to:

  • Microsoft Visual Basic for MS-DOS
  • Microsoft Basic Professional Development System for MS-DOS 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 "Subscript Out Of Range".

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.

Modification Type:MinorLast Reviewed:8/16/2005
Keywords:KB75517