Microsoft KB Archive/37646

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 17:55, 18 July 2020 by 3155ffGd (talk | contribs) (importing KB archive)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Base


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