Microsoft KB Archive/182069

= BUG: Compile Error on Print Statement in a With..End Block =

Article ID: 182069

Article Last Modified on 5/13/2003

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q182069



SYMPTOMS
You invoke the Print method from within a With..End block, as follows: With Form1 .Print "Generates Error" End With When you run the project, the following error message is displayed:

Compile Error

Method or Data not found.



CAUSE
"Print" is a reserved word. If Print is used within a With statement, Visual Basic incorrectly parses the word.



RESOLUTION
Explicitly reference the object when invoking the Print method. For example, use the following code sample to eliminate this behavior: Form1.Print "Printed on the Form."



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.



Steps to Reproduce Behavior
 Start a new Standard EXE project in Visual Basic. Form1 is created by default.  Copy the following code to the Code window of Form1: Option Explicit

Private Sub Form_Click With Form1 .Print "Generates Error" End With

'To use the workaround code, comment the 'previous three lines and uncomment the 'following line:

'Form1.Print "Desired Behavior" End Sub  On the Run menu, click Start or press the F5 key to start the program. Click on the Form, and note that the following error message appears:

Compile Error

Method or Data not found.



Additional query words: kbVBp500bug kbVBp600bug kbVBp kbdsd kbDSupport kbCompiler

Keywords: kbbug kbpending KB182069

-

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

© Microsoft Corporation. All rights reserved.