Microsoft KB Archive/93673

= IF Statement With NOT Operator Can Fail When Compiled In VB =

PSS ID Number: 93673

Article Last Modified on 1/8/2003

-

The information in this article applies to:


 * Microsoft Visual Basic for MS-DOS 1.0

-



This article was previously published under Q93673



SYMPTOMS
When using the NOT operator in combination with the IF statement, your program may incorrectly jump on the wrong condition. This problem only occurs in compiled programs.



WORKAROUND
Some possible workarounds for this problem are listed below:


 * Do not use the NOT operator in an IF statement. Instead, use the NOT operator on the expression in a previous statement, then use the result of that expression in your IF statement.
 * Always use 0 for a logical FALSE and -1 for a logical TRUE.



STATUS
Microsoft has confirmed this to be a bug in the Standard and Professional Editions of Microsoft Visual Basic for MS-DOS, version 1.0. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.



MORE INFORMATION
In a compiled program, the IF statement in combination with the NOT operator works correctly if all expressions assume -1 is a logical TRUE and 0 is a logical FALSE. Normally Basic assumes any non-zero value to be a logical TRUE. In the case of a compiled program with an IF statement that uses the NOT operator, the outcome is inconsistent if you assume any non-zero value is a logical TRUE.

The following steps can be used to reproduce this problem:

  Compile the following program using the &quot;Make EXE File...&quot; menu item under the &quot;Run&quot; menu: a% = 1 ' Basic Assumes non-zero values to be TRUE. IF NOT a% THEN PRINT &quot;true&quot; ELSE PRINT &quot;false&quot;  Exit VBDOS.EXE and run the program.

The expression &quot;NOT a%&quot; should give -2, a non-zero (true) value. The program incorrectly outputs &quot;false&quot;. The interpreter environment correctly outputs &quot;true&quot;.

To work around this problem you can either replace the 1 in this example with -1, or use the NOT operator on the expression before performing the IF statement as follows: a% = NOT 1 IF a% THEN PRINT &quot;true&quot; ELSE PRINT &quot;false&quot;

Additional query words: VBmsdos BUGLIST1.00 1.00

Keywords: KB93673

Technology: kbAudDeveloper kbVB100DOS kbVBSearch kbZNotKeyword3

-

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

© 2004 Microsoft Corporation. All rights reserved.