In .EXE, PAINT Corrupts SUB Arugument Used as Color Value (69766)



The information in this article applies to:

  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5

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-

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

  3. 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
				

Modification Type:MinorLast Reviewed:1/9/2003
Keywords:KB69766