Microsoft KB Archive/37646

= FOR...NEXT with 32767 or -32768 Index Fails to Stop Unless /d =

Article ID: 37646

Article Last Modified on 11/21/2006



This article was previously published under Q37646



SUMMARY
If you use an integer for a FOR...NEXT loop counter, and the top of the loop is 32767 (when STEP is positive) or the bottom of the loop is -32768 (when STEP is negative), an overflow error will be correctly generated by QB.EXE or by the EXE compiled with /d. Without the /d, the loop does not stop at the top/bottom; it wraps around and executes indefinitely.

The problem occurs because overflow checking is only done when /d compiler switch is specified.



MORE INFORMATION
The following is a code example:

This program never finishes the FOR NEXT loop when compiled without /d. DEFINT A-Z FOR X = 1 TO 32767 IF X MOD 100 = 0 THEN PRINT X NEXT X

Additional query words: QuickBas

Keywords: KB37646

-

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

© Microsoft Corporation. All rights reserved.