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)
excel vba excel-2010
|
show 1 more comment
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)
excel vba excel-2010
In the text you mention "collection" but your code uses Dictionaries and arrays. IsreportDatathe same asmaster?
– 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 usingItem()though - you'd needyourArrayHere(0)to access the first item so something likereportData(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
|
show 1 more comment
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)
excel vba excel-2010
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
excel vba excel-2010
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. IsreportDatathe same asmaster?
– 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 usingItem()though - you'd needyourArrayHere(0)to access the first item so something likereportData(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
|
show 1 more comment
In the text you mention "collection" but your code uses Dictionaries and arrays. IsreportDatathe same asmaster?
– 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 usingItem()though - you'd needyourArrayHere(0)to access the first item so something likereportData(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
|
show 1 more comment
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
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Nov 21 at 19:21
Tim Williams
84.2k96482
84.2k96482
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
In the text you mention "collection" but your code uses Dictionaries and arrays. Is
reportDatathe same asmaster?– 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 needyourArrayHere(0)to access the first item so something likereportData(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