Microsoft KB Archive/149034

= FIX: OLE Control Updated Event Fired in Endless Loop =

Article ID: 149034

Article Last Modified on 6/28/2004

-

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 Q149034



SYMPTOMS
Interrupting normal execution in the Updated event of an OLE control can cause the Updated event to be fired repeatedly, in an endless loop. Displaying a modal form such as a dialog box causes this problem, as well as stepping through the code in debug mode. Execution does not happen in a normal fashion in both of these cases.



RESOLUTION
Although the code cannot be run in debug mode it does run correctly as a compiled executable provided no modal forms are shown in the Updated event. To show a modal form in response to an Updated event, you can enable a timer control in the Updated event and then have the Timer's Timer event show the form. For example: Private Sub OLE1_Updated(Code As Integer) Timer1.Enabled = True End Sub

Private Sub Timer1_Timer Timer1.Enabled = False MyForm.Show vbModal End Sub



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug has been fixed in Visual Basic 6.0.



Steps To Reproduce Issue
 Start Visual Basic 4.0. Form1 is created by default. Add a single OLE control to the form. When prompted to insert an object choose a Microsoft Excel worksheet or Microsoft Word document. The problem can occur using other objects also.  Add this code to the form: Private Sub Form_Click Dim i As Integer

i = FreeFile Open "test.ole" For Binary As i         OLE1.SaveToFile i          Close i      End Sub  Press F5 or click Start on the Run menu to run the application. Click once on the form to save the object to a file called Test.ole. Start another instance of Visual Basic 4.0. Form1 is again created by default. Add an OLE control to Form1. Click Cancel when prompted with the Insert Object dialog.</li>  Add this code to the form: Option Explicit

Private Sub Form_Click Dim i As Integer

i = FreeFile Open "test.ole" For Binary As i         OLE1.ReadFromFile i          Close i

OLE1.DoVerb vbOLEShow End Sub

Private Sub OLE1_Updated(Code As Integer) Debug.Print "Updated fired: " & Code End Sub </li> Press F5 or click Start on the Run menu to run the application. Click once on the form and see that the program runs fine. Now stop the application and press F8 to start the program in step mode. Click once on the form and step through the code loading the OLE object and into the Updated event. Keep stepping through the code and notice that the Updated event is fired continually.</li></ol>

Additional query words: kbVBp400bug kbVBp600fix kbVBp kbdsd kbDSupport kbOLE kbControl

Keywords: kbbug kbfix KB149034

-

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

© Microsoft Corporation. All rights reserved.