Results 1 to 6 of 6

Thread: Locked array

  1. #1

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Locked array

    I'm getting the error "This array is fixed or temporarily locked" when trying to perform this action:
    VB Code:
    1. ReDim Preserve Events(UBound(Events) + 1)
    The array is declare as dynamic... so, what's going on?
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  2. #2
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    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...

  3. #3
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357
    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?
    ~seaweed

  4. #4
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    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...

  5. #5
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357
    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:
    1. Private Events() As Integer
    2.  
    3. Private Sub Command1_Click()
    4.     ReDim Preserve Events(UBound(Events) * 2)
    5. End Sub
    6.  
    7. Private Sub Form_Load()
    8.     ReDim Preserve Events(1000000)
    9. End Sub
    Last edited by seaweed; Mar 26th, 2003 at 06:04 PM.
    ~seaweed

  6. #6

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Two things.. the one you mentioned, and don't try to redim it if you're inside an With-End With block. Thanks!
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width