Knowledge Base |

# Negative Array Subscripts Checked with Debug, /D

Article ID: 11880

Article Last Modified on 11/21/2006

This article was previously published under Q11880

## SUMMARY

Question:
I have two questions on subscripts in QuickBasic, as follows:

1. What is supposed to happen when I use negative array subscripts in QuickBasic?
2. Does QuickBasic check the validity of subscripts?

Response:
The following are responses to your questions:

1. Negative subscripts are not supported in Versions 3.00 and earlier, so when you use negative subscripts, the results are unpredictable. Versions 4.00 and later support the "TO" optional syntax, which allows for subscripts in the range of -32768 to 32767. However, invalid subscripts, such as negative values in Versions 3.00 and later, and subscripts out of range in all versions, are not checked for unless you have compiled with /D.
   For example, compile the following program with BC.EXE without /D:

             DIM A(10), B(10)
             A(9) = 1
             A(10) = 2
             PRINT B(-1)  'the value printed is 2, which is value of A(10)
             PRINT B(-2)  'the value printed is 1, which is the value of A(9)
             END

   Since Basic may move items around in memory, the above results might not occur if there were other operations between the assignment statements and the PRINT statements.
2. QuickBasic checks subscript range validity when the /D switch is on, or when the Debug option is selected in the editors in Versions 2.x and 3.00.

Additional query words: QuickBas BasicCom

Keywords: KB11880