BUG: Error 10 Attempting to ReDim or Erase an Array

ID: Q187553


The information in this article applies to:
  • Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, version 6.0
  • Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 32-bit only, for Windows, version 5.0


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.


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

  1. Start a new Standard EXE project in Visual Basic. Form1 is created by default.


  2. Place a CommandButton on Form1. Note that you will add code for the button in step 6.


  3. Add a new Module (Module1) to the project.


  4. In the Module1 code window, define the following user-defined type:
    
          Type MyType
            lTest as Long
          End Type
     


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


  6. 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
     


  7. Make the project and then run the EXE. When the form opens, click Command1 to reproduce the error mentioned above.



REFERENCES

For additional information, please see the following article in the Microsoft Knowledge Base:

Q176049 : BUG: Run-time Error "This Array is Fixed or Temporarily Locked"

Additional query words: kbDSupport kbdss kbVBp500bug kbNoKeyWord kbVBp600bug

Keywords : kbGrpVB
Version :
Platform : WINDOWS
Issue type : kbbug


Last Reviewed: January 5, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.