Microsoft KB Archive/320103

= BUG: Conditionally Compiled Public Events May Cause an Access Violation =

Article ID: 320103

Article Last Modified on 5/15/2002

-

APPLIES TO


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

-



This article was previously published under Q320103



SYMPTOMS
If you use conditionally compiled public events, you may receive an access violation in the Microsoft Visual Basic development environment. This error may occur during compilation or when you shut down the development environment.



CAUSE
This problem can occur if you use an Object Browser attribute to define and apply a public variable after the conditionally compiled public events.



RESOLUTION
To work around this problem, move any variables that have Object Browser attributes before any conditionally compiled public events.



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce the Problem
  Create a new ActiveX.dll project, and then paste the following code in the Class1 module: Option Explicit

'Move L here and everything will be fine! 'Public L As Long


 * 1) Const switch = False

Public Event ev1 Public Event ev2

Public Event Ev3 Public Event Ev4
 * 1) If switch Then
 * 1) End If

Public Event ev5

'L has had HelpID and Description attributes set with the Object Browser. 'Find L for your class in the Object Browser, and then select &quot;Properties.&quot;

Public L As Long

Public Event ev6  On the Tools menu, click Procedure Attributes. In the Name dialog box, click L. In the Description dialog box, type Test . In the Help Context ID dialog box, type 1 .</li> On the File menu, click Save, and then click Make the dll.</li> Create a new Standard Exe project. By default, Form1 is created.</li> On the Project menu, click References, select the reference to the ActveX.dll project that you just created, and then click OK.</li> Place a Command Button control on Form1.</li>  Open the form in code view, and then paste the following code: Private Sub Command1_Click 'Change Project1 to the name of the ActiveX.dll project that you just created. Dim x As Project1.Class1 Set x = New Class1 x.L = 5 MsgBox x.L End Sub </li> Run the project and you will receive the access violation.</li></ol>

Keywords: kbbug kbnofix kbactivexevents KB320103

-

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

© Microsoft Corporation. All rights reserved.