I'm getting the error "This array is fixed or temporarily locked" when trying to perform this action:The array is declare as dynamic... so, what's going on?VB Code:
ReDim Preserve Events(UBound(Events) + 1)
Printable View
I'm getting the error "This array is fixed or temporarily locked" when trying to perform this action:The array is declare as dynamic... so, what's going on?VB Code:
ReDim Preserve Events(UBound(Events) + 1)
You pass the array to a function (or sub) and THEN you are trying to redim it...
I had the same problem before (long time ago), and I think it's because VB thinks that the first function is still writing data into the array, and when it's writing into the array, it's locking it, and it will unlock it when it's done... probably you pass the variable to a function while it is locked...
Post the code yuou are using, to have a better idea of what it's going on...
I don't think that's it. The UBound function returns it's value first, then that value gets incremented by 1, and then the ReDim function resizes the array. I have used this many times without problems.
I do agree that posting more code would be helpfull, so we could get an idea of the context, because your snippet is fine on it's own. Do you happen to know the value of UBound(Events) when the break occurrs?
Isn't "Events" a keyword reserved by Visual Basic ???
I typed Events in vb and presst F1 to check, and it was saying "Keyword Not Found", but still, I would not declare a variable with that name, I would declare it like, myEvents, or... arrayEvents.... etc...
I think you're thinking about the WithEvents keyword?
The following works fine for me, although response time slowed dramatically when the array reached 128,000,000 members:VB Code:
Private Events() As Integer Private Sub Command1_Click() ReDim Preserve Events(UBound(Events) * 2) End Sub Private Sub Form_Load() ReDim Preserve Events(1000000) End Sub
Two things.. the one you mentioned, and don't try to redim it if you're inside an With-End With block. Thanks!