Microsoft KB Archive/248285
Article ID: 248285
Article Last Modified on 10/20/2003
- Microsoft Visual Basic 5.0 Enterprise Edition
- Microsoft Visual Basic 5.0 Professional Edition
This article was previously published under Q248285
If you try to edit the code for a form or UserControl that is hosting an instance of a UserControl (which is defined within the same project), the project cannot be edited. For example, if you modify a line of code, it reverts to its unmodified state when you move off the line.
If you continually try to edit the form or UserControl after the first try proves unsuccessful, you may receive one of the following error messages:
The control instance may lose its control class; that is, the control instance is no longer an instance of a UserControl but an instance of a picture box.
When a UserControl is in the design environment and is hosted on a form or UserControl, the UserControl is running. If the UserControl is defined in the same project as the host, when you edit the host's code, the Visual Basic editor raises the error message when the edit invalidates the procedural layout of the code.
There are two ways to work around this problem in Visual Basic 5.0:
- Develop the control in a separate project than its host. This is the preferred workaround.
- Comment out the ReadProperties and WriteProperties events in the UserControl before you edit the host.
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
This bug was corrected in Visual Basic 6.0.
Steps to Reproduce Behavior
- Create a new Standard EXE project in Visual Basic 5.0. Form1 is created by default.
- From the Project menu, add a new User Control to the project.
- Select the ReadProperties event in the User Control, and edit the code so that the stub for the function exists. You do not need to add any code.
- Close the design windows for the User Control, and add an instance of the control to Form1.
- Double-click the control instance to edit one of the event procedures for the control instance.
- Add three valid lines of code (such as MsgBox "Hello").
- Block comment this event procedure. To do this, add a single quotation mark (') to the beginning of each line. You can also highlight all of the code, and click Comment Block from the Edit toolbar.
Notice that only the first two lines of the procedure are commented out. (You may also receive one of the above-mentioned error messages.) Furthermore, you cannot add or edit any other lines of code; all that you can do is unload Visual Basic. Do not save your project at this stage because you may corrupt it.
This problem may also occur when you edit an Enum declaration in the declarations section of the form.
Additional query words: usercontrol uneditable invalid picturebox
Keywords: kbbug kbfix KB248285