+ Reply to Thread
Results 1 to 4 of 4

Putting a dynamic array in a dictionary

Hybrid View

  1. #1
    Registered User
    Join Date
    01-10-2013
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    15

    Putting a dynamic array in a dictionary

    Is it possible to put a dynamically calculated array in a VBA dictionary?

    What I have now is:

        Dim data As Object
        Dim Size As Integer 'for example it is actually a dynamically calculated number
        
        Set data = CreateObject("scripting.dictionary")
        Size = 3
        If Not (data.exists(5)) Then
            data.Add (5), Array(Size)
        End If
        
        data(5)(1) = 1  'gives a subscript out of range error
    Last edited by wizuriel; 01-16-2013 at 04:29 PM.

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Putting a dynamic array in a dictionary

    the array boundaries start at 0 so
    data(5)(0) = 1
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Registered User
    Join Date
    01-10-2013
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Putting a dynamic array in a dictionary

    Quote Originally Posted by JosephP View Post
    the array boundaries start at 0 so
    data(5)(0) = 1
    But I'm in theory setting the UBound to 3 so (1) should still exists and not give me that error

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Putting a dynamic array in a dictionary

    no you are not-you are adding a one element array containing the value 3 to the dictionary. if you want to create a dynamic array you don't use the Array operator you declare a dynamic array and then resize it
    Dim somearray()
    redim somearray(size)
    data.add 5, somearray

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1