Microsoft KB Archive/223116

= FIX: Public Type Statement Causes Application Error =

Article ID: 223116

Article Last Modified on 5/13/2003

-

APPLIES TO


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

-



This article was previously published under Q223116



SYMPTOMS
An ActiveX control project with a public user-defined variable and event is created. When the ActiveX control is placed in a Standard EXE project and then run from the IDE, the event executes properly. When the Standard EXE project is run using the compiled ActiveX control, attempting to execute the event in the ActiveX control generates the following error message:

Run-time Error '-2147417848(80010108)':

Method 'ReDimUDT' of object 'UserControl1' failed



RESOLUTION
To prevent this behavior, declare variables of a user-defined type in ActiveX controls as Private variables.



STATUS
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 Studio 6.0 Service Pack 3.

For more information about Visual Studio 6.0 Service Packs, please see the following articles in the Microsoft Knowledge Base:

194022 INFO: Visual Studio 6.0 Service Packs, What, Where, Why

194295 HOWTO: Tell That Visual Studio 6.0 Service Packs Are Installed



MORE INFORMATION
This section illustrates how to create a sample project that demonstrates this bug behavior. It assumes you are familiar with creating ActiveX controls, adding ActiveX controls to a Standard EXE project, and compiling a project.

Steps to Reproduce Behavior
Create the ActiveX Control:  Start a new Visual Basic 6.0 ActiveX Control project. UserControl1 is created by default.  Add the following code to the General Declarations section of UserControl1: Option Explicit

Public Type MyNewType MyNewType As String End Type

Private udtMyType As MyNewType

Public Sub ReDimUDT ReDim Preserve udtMyType(0) MsgBox "ReDIM UDT Event Executed." End Sub  On the File Menu, click Make Project1.ocx to create a compiled control. Save your project files for future reference.

Create the Standard EXE test project:  Create a new Standard EXE project. Form1 is created by default.</li> On the Project menu, click Components. Check the entry for the Project1 OCX and click OK.</li> Add a CommandButton and a UserControl1 to Form1.</li>  Copy the following code to the General Declarations section of Form1: Option Explicit

Private Sub Command1_Click UserControl11.ReDimUDT End Sub </li> Run the program and click the CommandButton. The error message given earlier is generated.</li></ol>

<div class="references_section">