Microsoft KB Archive/69766

= In .EXE, PAINT Corrupts SUB Arugument Used as Color Value =

Article ID: 69766

Article Last Modified on 11/21/2006

-

APPLIES TO


 * Microsoft QuickBasic 4.0
 * Microsoft QuickBASIC 4.0b
 * Microsoft QuickBasic 4.5 for MS-DOS

-



This article was previously published under Q69766



SYMPTOMS
In QuickBasic version 4.50, if a PAINT statement residing in a SUB or FUNCTION uses one of the SUB's arguments as its color parameter, then that particular SUB argument variable will be corrupted. This can cause bad values and incorrect results in subsequent calculations that rely on that variable within the SUB.

This is a confirmed problem with QuickBasic versions 4.00, 4.00b, and 4.50. This problem does not occur in Microsoft Basic Professional Development System (PDS) version 7.00 or 7.10.



MORE INFORMATION
This problem is caused by compiler optimizations, and can be worked around as follows:
 * 1) Disable optimizations by using the /X compiler option. -or-


 * 1) Disable optimizations by including the ON ERROR GOTO ... RESUME combination in the program source code. -or-


 * 1) To avoid the problem without disabling compiler optimizations, assign the SUB's argument to a local variable that is then passed to the PAINT statement's color parameter.

The following program reproduces the problem: DECLARE SUB box (z%) SCREEN 9               'Note: Also occurs in other graphics modes. FOR count% = 1 TO 10   'Run through the test with ten colors. CALL box(count%)       'Do the test. NEXT count% SLEEP                  'A chance to display the values. END

SUB box (z%) 'This sub uses z% for positioning as well as the color variable. x% = 200 + z% * 20 y% = 50 + z% * 20                      'Just a location for the box. LINE (x%, y%)-(x% + 10, y% + 10), z%, B 'The box to paint in. PRINT z%;                              'This value will be correct. PAINT (x% + 5, y% + 5), z%             'Do the paint. PRINT z%                    'This value will have been corrupted. END SUB

Additional query words: QuickBas SR# S910222-40 buglist4.50 fixlist7.00

Keywords: KB69766

-

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

© Microsoft Corporation. All rights reserved.