REDIM PRESERVE Only Allows Changing Rightmost Subscript

만료된 KB 콘텐츠 고지 사항

이 문서는 Microsoft에서 더 이상 지원하지 않는 제품에 대해 작성되었습니다. 따라서 이 문서는 “있는 그대로" 제공되며 더 이상 업데이트되지 않습니다.


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.

문서 ID: 75517 - 마지막 검토: 2005. 8. 16. - 수정: 1