Microsoft KB Archive/187553

= BUG: Error 10 Attempting to ReDim or Erase an Array =

Article ID: 187553

Article Last Modified on 5/13/2003

-

APPLIES TO


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

-



This article was previously published under Q187553



SYMPTOMS
When using arrays of user-defined types (UDTs) with a With statement inside a For loop, Visual Basic will not unlock the array when exiting the loop with an Exit For statement. If you attempt to re-dim or erase the array, the following run-time error is received:

Run-time error 10

This array is fixed or temporarily locked



RESOLUTION
Avoid using Exit For inside a With statement. A GoTo statement should be used instead.

NOTE: Be sure that the End With statement is executed. If the statement is not executed, you will receive the above error message.



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.



MORE INFORMATION
The array is locked because an array element is being pointed at by the With statement. The array is unlocked when you exit the With statement normally at End With, but is not unlocked when you exit the With statement early with Exit For.

Steps to Reproduce Behavior
 Start a new Standard EXE project in Visual Basic. Form1 is created by default. Place a CommandButton on Form1. Note that you will add code for the button in step 6. Add a new Module (Module1) to the project.  In the Module1 code window, define the following user-defined type: Type MyType lTest as Long End Type

  Move to the Form1 code window. In the General Declarations define a dynamic array as follows: Dim MyArray As MyType

  In the Form1 code window, select the (Command1) object, and enter the code for Command1_Click as follows: Private Sub Command1_Click ReDim MyArray(5) Dim i As Long, k As Long

For i = 0 To 5 With MyArray(i) .lTest = i             If i = 3 Then Exit For End With Next i

Erase MyArray End Sub

</li> Make the project and then run the EXE. When the form opens, click Command1 to reproduce the error mentioned above.</li></ol>

<div class="references_section">