Hello Everybody,
I have following issue:
Basically, I want to store arrays of distinct object types generically (so, in Variants) and retrieve them elsewhere into an Object array.
Firstly, if I cast an concrete array into an abstract one (i.e., in an Object array) and back, it won’t work, but if I store the abstract in a variant, then back, it works.
Secondly, the same thing upside-down - concrete into variant and then into abstract - is not working.
I hope following snippet shows, what I want to do:
Dim concrete(), concreteBack() As Dictionary
Dim abstract() As Object = concrete
abstract.Append(new Dictionary("a" : "b"))
'concreteBack = abstract 'this line won't compile
Dim temp As Variant = abstract
concreteBack = temp
'abstract = temp 'this line raises an TypeMismatchException
MsgBox(concrete(0).Value("a") + ", " + concreteBack(0).Value("a"))
Is there anyone who can explain me why the out commented lines are not working?
Or how I can tell the compiler, that in line 4 ‘abstract’ has the right type?
I have a workaround in mind, where i define a container which stores an object array and a variant, but i’d prefer it to manage ALL types in a single variant and this is, I believe, the idea behind variants.
Thank You,
Christopher