Microsoft KB Archive/176641

= FIX: Do Until Loop Evaluates "True" as -1 Exclusively =

Article ID: 176641

Article Last Modified on 11/18/2003

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition

-



This article was previously published under Q176641



SYMPTOMS
A Do Until loop that uses a literal or a variable of type Integer as a conditional will execute endlessly if the value is not -1.



RESOLUTION
Use a variable of type Variant or Long as the conditional argument for the loop.



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug has been fixed in Visual Basic 6.0.



MORE INFORMATION
Visual Basic defines "True" to mean "non-zero." Any value that is not zero should be evaluated as True. The Do Until loop in Visual Basic 5.0, however, evaluates only -1 as True if a literal value or a variable of type integer is used for the conditional argument.

Steps to Reproduce Behavior
Method 1:

  Place the following code on a CommandButton on a Visual Basic 5.0 form: Debug.Print "A" Do Until 3 Debug.Print "B" Loop Debug.Print "C"  Click the button. This loop will print "B" endlessly. (Press CTRL-BRK to stop execution.)

Method 2:

  Place the following code on a CommandButton on a Visual Basic 5.0 form: Dim i As Integer i = 3 Debug.Print "A" Do Until i        Debug.Print "B" Loop Debug.Print "C"  Click on the button. This loop will print "B" endlessly. (Press CTRL-BRK to stop execution.)

NOTE: In both cases, the loop that prints "B" should not execute.</ol>

Additional query words: infinite loop iterate kbVBp500bug kbVBp600fix kbVBp kbdsd kbDSupport kbVBA

Keywords: kbbug kbfix KB176641

-

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

© Microsoft Corporation. All rights reserved.