Microsoft KB Archive/41536

= PRINT TAB Can Change Value of Parameter in Subprogram =

Article ID: 41536

Article Last Modified on 11/21/2006



This article was previously published under Q41536



SYMPTOMS
The code below demonstrates that a variable that has been passed to a subprogram procedure may incorrectly be changed by a PRINT TAB(n) statement. However, the same statement in the main module does not cause the error.

The problem can be avoided by not using the PRINT TAB(n) statement, or by assigning a local variable to the passed parameter in the SUB and using the local variable in the PRINT TAB(n) statement, or by compiling with the BC /X option. (The /X compiler switch is normally used only to flag an ON ERROR statement with RESUME, RESUME NEXT, or RESUME 0.)



STATUS
Microsoft has confirmed this to be a bug in an .EXE program compiled with BC.EXE in QuickBasic version 4.5. No problem occurs in the QB.EXE environment. This problem was corrected in Microsoft Basic Professional Development System (PDS) version 7.1 (fixlist7.10).



MORE INFORMATION
The program example below works correctly with all versions of QuickBasic earlier than version 4.5.

Code Example
DECLARE SUB testsub (row%) row% = 9 ' this line is ok -- it is in the main module LOCATE row%, 1: PRINT &quot;main line row%= &quot;; row%; TAB(38); row%; row% = 10 CALL testsub(row%) END

SUB testsub (row%) LOCATE row%, 1: PRINT &quot;Sub row%= &quot;; row%; ' The value of row% prints incorrectly: PRINT TAB(38); &quot;row now = &quot;; row% END SUB To work around the problem in QuickBasic 4.5, print a local variable instead of the passed parameter, for example: SUB testsub (row%) x%=row% LOCATE row%, 1: PRINT &quot;Sub row%= &quot;; row%; PRINT TAB(38); &quot;row now = &quot;; x%     ' x% prints ok. END SUB

Additional query words: QuickBas 4.50 buglist4.50

Keywords: KB41536

-

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

© Microsoft Corporation. All rights reserved.