IF Statement With NOT Operator Can Fail When Compiled In VB

ID: Q93673


The information in this article applies to:
  • Microsoft Visual Basic Standard and Professional Editions for MS-DOS, version 1.0


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:

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


  2. Exit VBDOS.EXE and run the program.


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

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 "true" ELSE PRINT "false" 

Additional query words: VBmsdos BUGLIST1.00 1.00

Keywords :
Version : MS-DOS:1.0
Platform : MS-DOS
Issue type :


Last Reviewed: December 10, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.