Microsoft KB Archive/57926

= &quot;Subscript out of Range&quot; Long-Integer Array in IF/THEN in 4.50 =

Article ID: 57926

Article Last Modified on 11/21/2006



This article was previously published under Q57926



SYMPTOMS
The QuickBasic Version 4.50 program shown below produces a &quot;Subscript out of range&quot; error if compiled with the BC /D (debug) switch. This appears to be caused by a compiler optimization problem for the particular combination of using a long-integer variable to subscript a long-integer array in an IF ... THEN statement.

If the program is run from the QB.EXE environment or is not compiled with the BC /D switch, the error does not occur.



STATUS
Microsoft has confirmed this to be a bug in Microsoft QuickBasic Version 4.50. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

This problem does not occur in versions of QuickBasic prior to Version 4.50, in Microsoft Basic Compiler Versions 6.00 and 6.00b for MS-DOS and MS OS/2, or in Microsoft Basic Professional Development System (PDS) Version 7.00 for MS-DOS and MS OS/2.



MORE INFORMATION
The following program exhibits the behavior: DIM a(10) AS LONG a(1) = 5 k&amp; = 5 i&amp; = 1 IF a(i&) = k& THEN a(i&) = -k&      'this statement causes the error to occur END IF Compile and link the program as follows: BC /D TEST; LINK TEST; The &quot;Subscript out of range&quot; error does not occur if the IF ... THEN syntax is removed or if the variables i and k are of any type other than long integers.

To work around the problem, replace the problem-assignment statement, a(i&) = -k&, with either of the following equivalent assignments:


 * 1) a(i&) = k&

a(i&) = -a(i&)
 * 1) a(i&) = -a(i&)

Additional query words: QuickBas buglist4.50

Keywords: KB57926

-

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

© Microsoft Corporation. All rights reserved.