BUG: IF Statement with POS Function Problem in Decimal QB (84384)






This article was previously published under Q84384

SYMPTOMS

The following code evaluates differently within the interpreters of the binary and decimal versions of QuickBasic for the Macintosh:
   FOR I = 1 TO 5
     PRINT "1";
     ' POS returns the current horizontal column position of
     ' text printed to the output window
     IF I + 1 <> POS(n) THEN BEEP
   NEXT I
   ' wait for mouse click to continue
   WHILE MOUSE(0) = 0 : WEND
				
The binary version of QuickBasic for the Macintosh works correctly (with no beeps) and the decimal version of QuickBasic for the Macintosh behaves incorrectly (as shown with a beep). Running in the decimal version will cause five beeps at run time. The above code executes correctly as an application compiled from either version of QuickBasic for the Macintosh.

Microsoft has confirmed this to be a bug with Microsoft QuickBasic versions 1.0, 1.0a, and 1.0b for the Macintosh . We are researching this problem and will post new information here as it becomes available.

MORE INFORMATION

Adding the following debugging lines will show that the problem is not caused by the POS function, but rather by the way the IF THEN condition is parsed:
   DIM x(5), y(5)
   FOR I = 1 TO 5
     PRINT "1";
     ' POS returns the current horizontal column position of
     ' text printed to the output window
     IF I + 1 <> POS(n) THEN BEEP
     ' assign values returned by POS and I + 1 to variables
     x(I) = I + 1
     y(I) = POS(n)
   NEXT I
   PRINT
   ' print out values of debug arrays
   FOR I = 1 to 5
     PRINT x(I), y(I)
   NEXT
   ' wait for mouse click to continue
   WHILE MOUSE(0) = 0 : WEND
				
The output of the program will be as follows in either the decimal or binary version of QuickBasic:
   11111
   2   2
   3   3
   4   4
   5   5
   6   6
				
This output is as expected. The decimal version of QuickBasic is not evaluating the left side of the IF THEN clause (I + 1) correctly.

Workarounds

If you put parentheses around the "I + 1" part of the IF clause, the decimal version also works properly. For example, insert the following IF statement into the code in place of the current IF statement:
   IF (I+1) <> POS(n) THEN BEEP
				
When you run the program, a beep will not sound. This means that with the parentheses, the IF statement is being evaluated correctly.

When the programs are compiled they also work correctly (meaning no beeps) in either the binary or decimal QuickBasic interpreter.

Modification Type: Minor Last Reviewed: 1/9/2003
Keywords: kbbug KB84384