Microsoft KB Archive/141879

= PRB: Print Function Evaluation Order Has Changed =

Article ID: 141879

Article Last Modified on 12/9/2003

-

APPLIES TO


 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 16-bit Enterprise Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

-



This article was previously published under Q141879



SYMPTOMS
The order of evaluation of the arguments to the Print statement differs in Visual Basic 3.0 and Visual Basic 4.0.



CAUSE
All products that use Visual Basic for Applications, including Visual Basic 4.0, evaluate all function calls contained within a Print statement first, before any printing is done. Visual Basic 3.0 evaluates functions while executing the Print statement.



STATUS
This behavior is by design. The order of evaluation of multiple functions within an expression is undefined and may change from version to version. This is documented at the end of the online Help for the Function statement.



Steps to Reproduce Behavior
 Start Visual Basic. On the File menu, click New Project. Double-click the command button box on the toolbar (symbolized by a shaded oval). This will display a command button named Command1 on the form.  Add the following code to the general declarations section of Form1: Function Test(N As Integer) As Integer N = N + 1 Test = N     End Function   Add the following code to the command buttons click event: Sub Command1_Click Dim M As Integer M = 1 Form1.Print M, Test(M), M, Test(M) End Sub  On the Run menu, click start (ALT, R, S) or press the F5 key.</li></ol>

The following chart illustrates the behavior of this program under Visual Basic 3.0 and Visual Basic 4.0: <pre class="fixed_text">                      Print M    Test(M)    M    Test(M)

Visual Basic 3.0        1          2          2     3 Visual Basic 4.0        3          2          3     3 Visual Basic 3.0 evaluates functions while processing the Print statement. Because Visual Basic 4.0 uses Visual Basic for Applications, all functions are evaluated first, before any printing is done.

Keywords: kbprogramming kbprb KB141879

-

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

© Microsoft Corporation. All rights reserved.