Microsoft KB Archive/84384

= BUG: IF Statement with POS Function Problem in Decimal QB =

Article ID: 84384

Article Last Modified on 11/21/2006



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 &quot;1&quot;; ' 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 &quot;1&quot;; ' 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 &quot;I + 1&quot; 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.

Additional query words: MQuickB 1.00 1.00a 1.00b

Keywords: kbbug KB84384

-

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

© Microsoft Corporation. All rights reserved.