Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

This array is fixed or temporarily locked (Error 10) 1

Status
Not open for further replies.

mattKnight

Programmer
May 10, 2002
6,238
GB
I am getting this error with the following code; MSDN suggests that the cause is I am passing a module level array. I only pass indices to/from functions.

module level
Code:
Private udtLink() As LinkedListHolder

Function
Code:
'---------------------------------------------------------------------------------------
' Project   : Project2 FormSizevbp.vbp
' Module    : modSubClass modSubClass.bas
' Procedure : Function DeleteLinkedMember
' DateTime  : 18/07/2005 09:43
' Author    : Matthew Knight
' Purpose   : Deletes Linked list member
'---------------------------------------------------------------------------------------
'
Private Function DeleteLinkedMember(lngIndex As Long) As Boolean

    Dim blnResult As Boolean
    Dim lngPrevious As Long
    Dim lngNext As Long
    
    Dim lngCount As Long
    

    For lngCount = lngIndex To UBound(udtLink) - 1
        'Temporary Store index values
        
        lngPrevious = udtLink(lngIndex).nPreviousIndex
        lngNext = udtLink(lngIndex).nNextIndex
        ' Shuffle array members down in memory
        ' Len(udtLink) = 20
        '
        CopyMemory udtLink(lngIndex), udtLink(lngIndex + 1), 20
        ' Write back index values
        
        udtLink(lngIndex).nPreviousIndex = lngPrevious
        udtLink(lngIndex).nNextIndex = lngNext
    Next lngCount
    'Redimension array to 1 smaller than it was
    lngCount = UBound(udtLink) - 1
[COLOR=red]
    'Error 10 Fixed array or temporarily locked at this redim line
    ReDim Preserve udtLink(0 To lngCount) As LinkedListHolder[/color]
    DeleteLinkedMember = blnResult

End Function

Anyone suffered from this before? and its hard to debug as this routine is part of a subclassed control...

As ever, further questions or more code snippets needed - ask me!

Thanks

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Thanks Hypetia,

I had already looked at that but none of it really fits;
[ol]
[li]The array is not fixed-size. Indeed I sucessfully call redim in order to increase the size when I put data in[/li]

[li]As far as I can see, I don't pass elements of the array between functions. I pass the index of the element i wish to process. If I am passing the element, it must be in some inherent fashion (maybe using Ubound or Lbound).[/li]

[li]The array is typed as a UDT, with all members typed as long i.e. there are no variables of type variant.[/li]
[/ol]

Only cause 2 seems anywhere close to fitting, but I can't see where or why VB is keeping a lock on the array...

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Solved it!

Item 2 was the cause! In other routines, I was passing members on an element in a function call.

i.e the old code

Code:
    With mudtLink(lngIndex).udtWindowInfo
            Call SetWindowLong(.hWnd, GWL_WNDPROC, .pOldWndProc)
    End With

now
Code:
Dim lngWProc As Long
Dim lngHwnd As Long
    With mudtLink(lngIndex)
    lngWProc = .pOldWndProc
    lngHwnd = .hWnd
    End With
    
    Call SetWindowLong(lngHwnd, GWL_WNDPROC, lngWProc)

Thanks for making me think it through!

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Glad that the problem is solved. I was suspecting the same, that the array is being locked somewhere else in the call stack.

I was going to suggest to make a trap by checking the locked state of your array at different potential places in your code, by using the following function.
___
[tt]
'checked the locked state of the array
Public Function IsLocked() As Boolean
On Error Resume Next
ReDim Preserve udtLink(LBound(udtLink) To UBound(udtLink))
IsLocked = Err = 10
End Function[/tt]
___

And inserting this check at various potential places in code.
[tt]
Debug.Assert IsLocked = False
[/tt]
It causes the code to break as soon as your array gets locked.

But I think you don't need it now. The problem is solved.:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top