Hopefully a quick question. I’m trying to learn about the roAssociativeArray, and created the following, but am getting an error “Member function not found in BrightScript Component or interface.”
Why doesn’t this work ( I copied basic syntax from a previous demo )?
Sub Main()
Web = SetAssociativeArray()
Web.ThisIsOne()
End Sub
Function SetAssociativeArray() As Object
Print "Set Array"
Web = CreateObject("roAssociativeArray")
Web.ThisIsOne = One
Web.ThisIsTwo = Two
End Function
Sub One()
Print "Hit One"
End Sub
Sub Two()
Print "Hit Two"
End Sub
A demo project does something similar, and it compiles, so not sure what my issue is? Any advice?
Thanks
Bud
Your SetAssociativeArray function never returns an object. Add a “Return Web” to the end of it, and you should be in business.
Jeeze, man what a silly mistake. Worked like a charm.
Thanks Endless, you are the best.
Regards
Bud
Sure thing.. it may also be worth noting that your SetAssociativeArray function can be written using a different syntax that you might find preferable:
Function SetAssociativeArray() As Object
Web = {
ThisIsOne: One
ThisIsTwo: Two
}
Return Web
End Function
Cool! That does read very nice. I’ve seen that in the reference guide, but hadn’t spent any time reading about it.
To be sure, it still creates a AssociativeArray, but I just don’t have to declare it with “CreateObject” like in my earlier code block?
Best
Bud
Correct. Another shortcut for creating an roAssociativeArray is this syntax:
Web = {} ' creates empty roAssociativeArray
Web.ThisIsOne = One
Web.ThisIsTwo = Two
-JT