brocker
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2011
10:40 AM
Storing an Associative Array in a AssociativeArray
Hey All,
I'm trying to store an Associative Array within a Associative Array with code similar to the following:
But when I get the Associative Array back, and try to use the ".AA", it is giving me a type of "INVALID". Is what I'm doing possible?
Thanks
Bud
I'm trying to store an Associative Array within a Associative Array with code similar to the following:
Function SetValues() As Object
'Create AA
aa_StudioData = CreateObject("roAssociativeArray")
aa_PosterItems = CreateObject("roAssociativeArray")
'Populate Items
aa_PosterItems.Value1 = "Foo"
aa_PosterItems.Value2 = "Foo2"
aa_PosterItems.Value3 = "Foo3"
'Populate
aa_StudioData.Count = 3
aa_StudioData.AA = aa_PosterItems
'Return Populated AA
Return aa_StudioData
End Fuction
Sub GetValues()
'Create AA
aa_Populated = CreateObject("roAssociativeArray")
aa_StudioDataList = CreateObject("roAssociativeArray")
'Populate AA List
aa_Populated = SetValues()
aa_StudioDataList = aa_Populated.AA
If aa_StudioDataList = invalid Then
Print("Invalid") <<==== ALWAYS HITS
End If
End Sub
But when I get the Associative Array back, and try to use the ".AA", it is giving me a type of "INVALID". Is what I'm doing possible?
Thanks
Bud
6 REPLIES 6


Roku Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2011
10:59 AM
Re: Storing an Associative Array in a AssociativeArray
You can certainly assign an AA as an attribute of another AA. The code you posted works for me in 3.0 and 4.1. At the end of GetValues(), aa_StudioDataList is an AA that looks like this...
{Value1: "Foo", Value2: "Foo2", Value3: "Foo3"}
brocker
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2011
11:21 AM
Re: Storing an Associative Array in a AssociativeArray
Thanks Chris,
One thought, do you think it would make a difference if one of the values in the AA is a "roArray"? Would that corrupt anything? One of the other items I store is a roArray (just didn't include it with the sample code).
I did notice if I did a "For Each" loop like the following:
It prints the item name, but how would I parse through each value in the AA to find what I'm looking for? Everything I've tried comes back as "INVALID".
Any thoughts
Thanks
Bud
PS - I forgot to mention I'm running 4.1 on the Roku 2.
One thought, do you think it would make a difference if one of the values in the AA is a "roArray"? Would that corrupt anything? One of the other items I store is a roArray (just didn't include it with the sample code).
I did notice if I did a "For Each" loop like the following:
For Each item in aa_StudioDataList
Print(item)
End For
It prints the item name, but how would I parse through each value in the AA to find what I'm looking for? Everything I've tried comes back as "INVALID".
Any thoughts
Thanks
Bud
PS - I forgot to mention I'm running 4.1 on the Roku 2.


Roku Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2011
11:34 AM
Re: Storing an Associative Array in a AssociativeArray
Have you tried the Lookup() function?
For Each item in aa_StudioDataList
Print item + ":" + aa_StudioDataList.Lookup(item)
End For
brocker
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2011
11:53 AM
Re: Storing an Associative Array in a AssociativeArray
Yeah, I get a "Type Mismatch" error.
I was thinking that I get this because the AA is INVALID when I run a check on the object as follows
If the compiler doesn't recognize the aa_StuidioDataList as a AA, then trying to do the "Lookup()" would throw an error wouldn't it?
Thanks
Bud
I was thinking that I get this because the AA is INVALID when I run a check on the object as follows
If aa_StudioDataList = invalid Then
Print("INVALID")
End If
If the compiler doesn't recognize the aa_StuidioDataList as a AA, then trying to do the "Lookup()" would throw an error wouldn't it?
Thanks
Bud


Roku Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2011
11:59 AM
Re: Storing an Associative Array in a AssociativeArray
"brocker" wrote:
If the compiler doesn't recognize the aa_StuidioDataList as a AA, then trying to do the "Lookup()" would throw an error wouldn't it?
Actually, if aa_StuidioDataList were invalid, I'm pretty sure you'd get something like "dot operator attempted with invalid object". If you're getting a type mismatch, something else must be going wrong. Using the code in your OP, aa_StuidioDataList does end up being an AA and the Lookup() method works.
brocker
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2011
12:07 PM
Re: Storing an Associative Array in a AssociativeArray
Really strange, well I guess it's good to know that what I'm trying to do is possible, but something is amiss. I'll go back and verify what I'm doing, I prob did some silly thing somewhere.
Thanks for your help Chris, I'll post back with any findings or further clarifications.
Regards
Bud
Thanks for your help Chris, I'll post back with any findings or further clarifications.
Regards
Bud