Microsoft KB Archive/161305

= PRB: "Hash Marks" on ActiveX Controls After Run-Time Error =

Article ID: 161305

Article Last Modified on 11/5/2003

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Control Creation Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition

-



This article was previously published under Q161305



SYMPTOMS
After receiving an error message, all instances of the ActiveX control are disabled and drawn with "hash marks."



CAUSE
This behavior occurs after an unhandled error in event code.



RESOLUTION
The conditions listed below must be met to avoid this problem:


 * 1) Ensure that the event code never generates a run-time error or that it handles all errors with an error handler.
 * 2) Never use Err.Raise within a UserControl.



STATUS
This behavior is by design.



MORE INFORMATION
Unhandled errors in event procedures are fatal to your control component's operation and the application using it because there is no procedure on the call stack to handle the error.

It is safe to raise errors in property procedures and methods, however, because properties and methods are always invoked by other procedures and errors you raise can be handled by the user in those procedures.

Steps to Reproduce Behavior
  Create an ActiveX control called "UserCtrl" with no constituent controls and the following code: Option Explicit

Private Procedure UserControl_Click Err.Raise 999, "UserControl", "Don't Click on Me" End Sub

Public Sub BackColor(ByVal NewVal As Long) UserCtrl.BackColor = NewVal Err.Raise 555, "UserControl", "Don't invoke this method" End Sub  Make an OCX. Create a new project and add the OCX via the Project|Components menu. Add your control and a CommandButton to the form.  Add the following code to the CommandButton's Click event: Sub Command1_Click On Error Resume Next UserCtrl1.BackColor 0 End Sub </li> Run the form and click the button. Then click your control.

When you click the CommandButton, nothing happens; the error is trapped and dealt with (ignored in this case).

When you click your control, you see the error message and, when dismissed, the control is disabled and becomes hashed out.</li></ol>

<div class="references_section">