Microsoft KB Archive/170357: Difference between revisions
(importing KB archive) |
m (Text replacement - """ to """) |
||
Line 50: | Line 50: | ||
<div class="errormessage"> | <div class="errormessage"> | ||
"VB caused a General Protection Fault in module VBA2.DLL" | |||
</div> | </div> | ||
Line 56: | Line 56: | ||
<div class="errormessage"> | <div class="errormessage"> | ||
"Run-time Error 9:<br /> | |||
Subscript Out of Range | Subscript Out of Range" | ||
</div> | </div> | ||
Line 63: | Line 63: | ||
<div class="errormessage"> | <div class="errormessage"> | ||
"An error has occurred in your program" | |||
</div> | </div> | ||
After clicking the | After clicking the "Ignore" button several times, another dialog box will report: | ||
<div class="errormessage"> | <div class="errormessage"> | ||
"Run time error '5': Invalid procedure call" | |||
</div> | </div> | ||
Line 75: | Line 75: | ||
<div class="errormessage"> | <div class="errormessage"> | ||
"An error has occurred in your application" | |||
</div> | </div> | ||
After clicking | After clicking "Ignore" twice, you will see: | ||
<div class="errormessage"> | <div class="errormessage"> | ||
"Run time error '458'<br /> | |||
Variable uses an OLE type not supported in Visual Basic | Variable uses an OLE type not supported in Visual Basic" | ||
</div> | </div> | ||
Line 115: | Line 115: | ||
Private Sub Class_Initialize() | Private Sub Class_Initialize() | ||
MyCollection.Add | MyCollection.Add "Hello" | ||
End Sub | End Sub | ||
</pre> | </pre> | ||
Line 123: | Line 123: | ||
Private Sub Class_Initialize() | Private Sub Class_Initialize() | ||
Set MyCollection = New Collection | Set MyCollection = New Collection | ||
MyCollection.Add | MyCollection.Add "Hello" | ||
End Sub | End Sub | ||
</pre> | </pre> | ||
Line 148: | Line 148: | ||
Private Sub Class_Initialize() | Private Sub Class_Initialize() | ||
MyCollection.Add | MyCollection.Add "Hello" | ||
End Sub | End Sub | ||
</pre></li> | </pre></li> | ||
Line 160: | Line 160: | ||
End Sub | End Sub | ||
</pre></li> | </pre></li> | ||
<li>Click Options on the Tools menu. Select the Project tab, set the Startup Form to | <li>Click Options on the Tools menu. Select the Project tab, set the Startup Form to "Sub Main" and click OK.</li> | ||
<li>Press the F5 key to run the project. You will receive one of the errors described at the beginning of this article.</li> | <li>Press the F5 key to run the project. You will receive one of the errors described at the beginning of this article.</li> | ||
<li><p>To work around this problem, modify the code in the class module so that it resembles the following:</p> | <li><p>To work around this problem, modify the code in the class module so that it resembles the following:</p> | ||
Line 167: | Line 167: | ||
Private Sub Class_Initialize() | Private Sub Class_Initialize() | ||
Set MyCollection = New Collection | Set MyCollection = New Collection | ||
MyCollection.Add | MyCollection.Add "Hello" | ||
End Sub</pre></li></ol> | End Sub</pre></li></ol> | ||
Latest revision as of 11:05, 21 July 2020
Article ID: 170357
Article Last Modified on 1/11/2001
APPLIES TO
- Microsoft Visual Basic 4.0 Professional Edition
- Microsoft Visual Basic 4.0 16-bit Enterprise Edition
This article was previously published under Q170357
SYMPTOMS
With the 16-bit version of Microsoft Visual Basic 4.0, if you attempt to access a collection of a class, you may receive one of the following errors.
When running in Microsoft Windows 3.11 or Microsoft Windows For Workgroups 3.11, the error will say:
-or-
When running in Microsoft Windows 95, the dialog box will report:
After clicking the "Ignore" button several times, another dialog box will report:
When running in Microsoft Windows NT or Windows 2000:
After clicking "Ignore" twice, you will see:
When running in Microsoft Windows 98, a dialog box will report:
CAUSE
This error will occur under the following circumstances:
- The Class module is in the same project as the code that accesses the collection. -and-
- The Public property of the class module is True. -and-
- The collection is not explicitly instantiated before you access it. In other words, the collection is implicitly instantiated with the New keyword when the collection is dimensioned.
RESOLUTION
To work around this problem, explicitly instantiate the collection. For example, if you are receiving one of the errors described above with the following code:
Public MyCollection As New Collection Private Sub Class_Initialize() MyCollection.Add "Hello" End Sub
Change the code to look like the following:
Public MyCollection As Collection Private Sub Class_Initialize() Set MyCollection = New Collection MyCollection.Add "Hello" End Sub
STATUS
Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.
MORE INFORMATION
Steps to Reproduce Behavior
- Start a new project.
- Click Class Module on the Insert menu to add a class module to the project.
Type the following code in the code window of the class module:
Public MyCollection As New Collection Private Sub Class_Initialize() MyCollection.Add "Hello" End Sub
- With the class module active, press the F4 key to display the property sheet. Set the Public property to True.
- Click Module on the Insert menu to add a module to the project.
Type the following code in the code window of the module:
Sub Main() Dim obj As New Project1.Class1 MsgBox obj.MyCollection.Item(1) Set obj = Nothing End Sub
- Click Options on the Tools menu. Select the Project tab, set the Startup Form to "Sub Main" and click OK.
- Press the F5 key to run the project. You will receive one of the errors described at the beginning of this article.
To work around this problem, modify the code in the class module so that it resembles the following:
Public MyCollection As Collection Private Sub Class_Initialize() Set MyCollection = New Collection MyCollection.Add "Hello" End Sub
Additional query words: gpf 0005:1E3A 0005:1B21 0005:2027
Keywords: kb16bitonly kbprb KB170357