VBA Accessing data structure











up vote
0
down vote

favorite












I have this really complicated data structure which I am trying to access. The reason I set it up like this is because I want to have a structure of each report containing all the questions for that report with all the data for each question. Please see the code below to understand what I am doing.



Dim master As New Dictionary      
Dim child As New Dictionary


this happens for each question in a report. Note in the end coll1-coll6 is what I want to print out



'coll# is a collection 
child.Add ID, Array(coll1, coll2, coll3, coll4, coll5, coll6)


this happens for each report in a list of reports to be created



master.Add reportNumber, child


Now I pass in each report one by one by doing this



master.key(i)


Given a report from the master.key(i) I want to be able to access the Array in child which contains all the collections



For Each key In reportData.Keys
Debug.Print reportData(key).Item(1).Item(1)
Next key


The above piece of code is me trying to print out the data from inside a report inside a question inside a collection for one of the questions



PS. I know this may seem convoluted but I saw it as the best solution to store a list of reports with all there data to make automatic reports.



In summary my question is how do I access my data which is inside a collection in a array.



Suggestions are welcome as to a better way to do what I am trying to accomplish. Which is essentially a frame work where I can automatically create reports.



I have changed the Array(coll1, ... , coll6) to a string to see if I can access it and it printed out correctly. So it looks like I am having troubles accessing the Array(coll1, ... , coll6)










share|improve this question
























  • In the text you mention "collection" but your code uses Dictionaries and arrays. Is reportData the same as master ?
    – Tim Williams
    Nov 21 at 18:38










  • No reportData is master.key(i)
    – User
    Nov 21 at 18:45










  • The dictionary reportData contains an Array of collections
    – User
    Nov 21 at 18:46










  • Sorry I totally missed the comment about the array contents being a collection. You can't access an array element using Item() though - you'd need yourArrayHere(0) to access the first item so something like reportData(key)(0).Item(1)
    – Tim Williams
    Nov 21 at 18:54












  • Debug.Print "Comment is: " & reportData(key)(counter).Item(1) Gives me an invalid procedure call error
    – User
    Nov 21 at 19:10















up vote
0
down vote

favorite












I have this really complicated data structure which I am trying to access. The reason I set it up like this is because I want to have a structure of each report containing all the questions for that report with all the data for each question. Please see the code below to understand what I am doing.



Dim master As New Dictionary      
Dim child As New Dictionary


this happens for each question in a report. Note in the end coll1-coll6 is what I want to print out



'coll# is a collection 
child.Add ID, Array(coll1, coll2, coll3, coll4, coll5, coll6)


this happens for each report in a list of reports to be created



master.Add reportNumber, child


Now I pass in each report one by one by doing this



master.key(i)


Given a report from the master.key(i) I want to be able to access the Array in child which contains all the collections



For Each key In reportData.Keys
Debug.Print reportData(key).Item(1).Item(1)
Next key


The above piece of code is me trying to print out the data from inside a report inside a question inside a collection for one of the questions



PS. I know this may seem convoluted but I saw it as the best solution to store a list of reports with all there data to make automatic reports.



In summary my question is how do I access my data which is inside a collection in a array.



Suggestions are welcome as to a better way to do what I am trying to accomplish. Which is essentially a frame work where I can automatically create reports.



I have changed the Array(coll1, ... , coll6) to a string to see if I can access it and it printed out correctly. So it looks like I am having troubles accessing the Array(coll1, ... , coll6)










share|improve this question
























  • In the text you mention "collection" but your code uses Dictionaries and arrays. Is reportData the same as master ?
    – Tim Williams
    Nov 21 at 18:38










  • No reportData is master.key(i)
    – User
    Nov 21 at 18:45










  • The dictionary reportData contains an Array of collections
    – User
    Nov 21 at 18:46










  • Sorry I totally missed the comment about the array contents being a collection. You can't access an array element using Item() though - you'd need yourArrayHere(0) to access the first item so something like reportData(key)(0).Item(1)
    – Tim Williams
    Nov 21 at 18:54












  • Debug.Print "Comment is: " & reportData(key)(counter).Item(1) Gives me an invalid procedure call error
    – User
    Nov 21 at 19:10













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have this really complicated data structure which I am trying to access. The reason I set it up like this is because I want to have a structure of each report containing all the questions for that report with all the data for each question. Please see the code below to understand what I am doing.



Dim master As New Dictionary      
Dim child As New Dictionary


this happens for each question in a report. Note in the end coll1-coll6 is what I want to print out



'coll# is a collection 
child.Add ID, Array(coll1, coll2, coll3, coll4, coll5, coll6)


this happens for each report in a list of reports to be created



master.Add reportNumber, child


Now I pass in each report one by one by doing this



master.key(i)


Given a report from the master.key(i) I want to be able to access the Array in child which contains all the collections



For Each key In reportData.Keys
Debug.Print reportData(key).Item(1).Item(1)
Next key


The above piece of code is me trying to print out the data from inside a report inside a question inside a collection for one of the questions



PS. I know this may seem convoluted but I saw it as the best solution to store a list of reports with all there data to make automatic reports.



In summary my question is how do I access my data which is inside a collection in a array.



Suggestions are welcome as to a better way to do what I am trying to accomplish. Which is essentially a frame work where I can automatically create reports.



I have changed the Array(coll1, ... , coll6) to a string to see if I can access it and it printed out correctly. So it looks like I am having troubles accessing the Array(coll1, ... , coll6)










share|improve this question















I have this really complicated data structure which I am trying to access. The reason I set it up like this is because I want to have a structure of each report containing all the questions for that report with all the data for each question. Please see the code below to understand what I am doing.



Dim master As New Dictionary      
Dim child As New Dictionary


this happens for each question in a report. Note in the end coll1-coll6 is what I want to print out



'coll# is a collection 
child.Add ID, Array(coll1, coll2, coll3, coll4, coll5, coll6)


this happens for each report in a list of reports to be created



master.Add reportNumber, child


Now I pass in each report one by one by doing this



master.key(i)


Given a report from the master.key(i) I want to be able to access the Array in child which contains all the collections



For Each key In reportData.Keys
Debug.Print reportData(key).Item(1).Item(1)
Next key


The above piece of code is me trying to print out the data from inside a report inside a question inside a collection for one of the questions



PS. I know this may seem convoluted but I saw it as the best solution to store a list of reports with all there data to make automatic reports.



In summary my question is how do I access my data which is inside a collection in a array.



Suggestions are welcome as to a better way to do what I am trying to accomplish. Which is essentially a frame work where I can automatically create reports.



I have changed the Array(coll1, ... , coll6) to a string to see if I can access it and it printed out correctly. So it looks like I am having troubles accessing the Array(coll1, ... , coll6)







excel vba excel-2010






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 at 18:25

























asked Nov 21 at 18:15









User

968




968












  • In the text you mention "collection" but your code uses Dictionaries and arrays. Is reportData the same as master ?
    – Tim Williams
    Nov 21 at 18:38










  • No reportData is master.key(i)
    – User
    Nov 21 at 18:45










  • The dictionary reportData contains an Array of collections
    – User
    Nov 21 at 18:46










  • Sorry I totally missed the comment about the array contents being a collection. You can't access an array element using Item() though - you'd need yourArrayHere(0) to access the first item so something like reportData(key)(0).Item(1)
    – Tim Williams
    Nov 21 at 18:54












  • Debug.Print "Comment is: " & reportData(key)(counter).Item(1) Gives me an invalid procedure call error
    – User
    Nov 21 at 19:10


















  • In the text you mention "collection" but your code uses Dictionaries and arrays. Is reportData the same as master ?
    – Tim Williams
    Nov 21 at 18:38










  • No reportData is master.key(i)
    – User
    Nov 21 at 18:45










  • The dictionary reportData contains an Array of collections
    – User
    Nov 21 at 18:46










  • Sorry I totally missed the comment about the array contents being a collection. You can't access an array element using Item() though - you'd need yourArrayHere(0) to access the first item so something like reportData(key)(0).Item(1)
    – Tim Williams
    Nov 21 at 18:54












  • Debug.Print "Comment is: " & reportData(key)(counter).Item(1) Gives me an invalid procedure call error
    – User
    Nov 21 at 19:10
















In the text you mention "collection" but your code uses Dictionaries and arrays. Is reportData the same as master ?
– Tim Williams
Nov 21 at 18:38




In the text you mention "collection" but your code uses Dictionaries and arrays. Is reportData the same as master ?
– Tim Williams
Nov 21 at 18:38












No reportData is master.key(i)
– User
Nov 21 at 18:45




No reportData is master.key(i)
– User
Nov 21 at 18:45












The dictionary reportData contains an Array of collections
– User
Nov 21 at 18:46




The dictionary reportData contains an Array of collections
– User
Nov 21 at 18:46












Sorry I totally missed the comment about the array contents being a collection. You can't access an array element using Item() though - you'd need yourArrayHere(0) to access the first item so something like reportData(key)(0).Item(1)
– Tim Williams
Nov 21 at 18:54






Sorry I totally missed the comment about the array contents being a collection. You can't access an array element using Item() though - you'd need yourArrayHere(0) to access the first item so something like reportData(key)(0).Item(1)
– Tim Williams
Nov 21 at 18:54














Debug.Print "Comment is: " & reportData(key)(counter).Item(1) Gives me an invalid procedure call error
– User
Nov 21 at 19:10




Debug.Print "Comment is: " & reportData(key)(counter).Item(1) Gives me an invalid procedure call error
– User
Nov 21 at 19:10












1 Answer
1






active

oldest

votes

















up vote
0
down vote













Seems like this is close to what you want:



Sub Tester()

Dim Master As New Dictionary
Dim child As New Dictionary, km, kc
Dim col1 As New Collection, col2 As New Collection

col1.Add "Hello"
col1.Add "World"
col2.Add "Blue"
col2.Add "Green"

child.Add "ID01", Array(col1, col2)

Master.Add "Key01", child

For Each km In Master.Keys
Debug.Print "Master key:", km '>> Key01
For Each kc In Master(km)
Debug.Print " Child key:", kc '>> ID01
Debug.Print , Master(km)(kc)(0)(1) '>> Hello
Debug.Print , Master(km)(kc)(0)(2) '>> World
Debug.Print , Master(km)(kc)(1)(1) '>> Blue
Debug.Print , Master(km)(kc)(1)(2) '>> Green
Next kc
Next km

End Sub





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418260%2fvba-accessing-data-structure%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    Seems like this is close to what you want:



    Sub Tester()

    Dim Master As New Dictionary
    Dim child As New Dictionary, km, kc
    Dim col1 As New Collection, col2 As New Collection

    col1.Add "Hello"
    col1.Add "World"
    col2.Add "Blue"
    col2.Add "Green"

    child.Add "ID01", Array(col1, col2)

    Master.Add "Key01", child

    For Each km In Master.Keys
    Debug.Print "Master key:", km '>> Key01
    For Each kc In Master(km)
    Debug.Print " Child key:", kc '>> ID01
    Debug.Print , Master(km)(kc)(0)(1) '>> Hello
    Debug.Print , Master(km)(kc)(0)(2) '>> World
    Debug.Print , Master(km)(kc)(1)(1) '>> Blue
    Debug.Print , Master(km)(kc)(1)(2) '>> Green
    Next kc
    Next km

    End Sub





    share|improve this answer

























      up vote
      0
      down vote













      Seems like this is close to what you want:



      Sub Tester()

      Dim Master As New Dictionary
      Dim child As New Dictionary, km, kc
      Dim col1 As New Collection, col2 As New Collection

      col1.Add "Hello"
      col1.Add "World"
      col2.Add "Blue"
      col2.Add "Green"

      child.Add "ID01", Array(col1, col2)

      Master.Add "Key01", child

      For Each km In Master.Keys
      Debug.Print "Master key:", km '>> Key01
      For Each kc In Master(km)
      Debug.Print " Child key:", kc '>> ID01
      Debug.Print , Master(km)(kc)(0)(1) '>> Hello
      Debug.Print , Master(km)(kc)(0)(2) '>> World
      Debug.Print , Master(km)(kc)(1)(1) '>> Blue
      Debug.Print , Master(km)(kc)(1)(2) '>> Green
      Next kc
      Next km

      End Sub





      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        Seems like this is close to what you want:



        Sub Tester()

        Dim Master As New Dictionary
        Dim child As New Dictionary, km, kc
        Dim col1 As New Collection, col2 As New Collection

        col1.Add "Hello"
        col1.Add "World"
        col2.Add "Blue"
        col2.Add "Green"

        child.Add "ID01", Array(col1, col2)

        Master.Add "Key01", child

        For Each km In Master.Keys
        Debug.Print "Master key:", km '>> Key01
        For Each kc In Master(km)
        Debug.Print " Child key:", kc '>> ID01
        Debug.Print , Master(km)(kc)(0)(1) '>> Hello
        Debug.Print , Master(km)(kc)(0)(2) '>> World
        Debug.Print , Master(km)(kc)(1)(1) '>> Blue
        Debug.Print , Master(km)(kc)(1)(2) '>> Green
        Next kc
        Next km

        End Sub





        share|improve this answer












        Seems like this is close to what you want:



        Sub Tester()

        Dim Master As New Dictionary
        Dim child As New Dictionary, km, kc
        Dim col1 As New Collection, col2 As New Collection

        col1.Add "Hello"
        col1.Add "World"
        col2.Add "Blue"
        col2.Add "Green"

        child.Add "ID01", Array(col1, col2)

        Master.Add "Key01", child

        For Each km In Master.Keys
        Debug.Print "Master key:", km '>> Key01
        For Each kc In Master(km)
        Debug.Print " Child key:", kc '>> ID01
        Debug.Print , Master(km)(kc)(0)(1) '>> Hello
        Debug.Print , Master(km)(kc)(0)(2) '>> World
        Debug.Print , Master(km)(kc)(1)(1) '>> Blue
        Debug.Print , Master(km)(kc)(1)(2) '>> Green
        Next kc
        Next km

        End Sub






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 at 19:21









        Tim Williams

        84.2k96482




        84.2k96482






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418260%2fvba-accessing-data-structure%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Lallio

            Unable to find Lightning Node

            Futebolista