I have a subclass cClassAB that is a subclass of ClassA and has an additional method (defined in an interface that the subclass implements).
I have a method that returns an array of ClassA (and I can’t change that as it comes from a plugin)
I would have liked to define a recipient array as
dim myABarray() as cClassAB = response.ClassAarray
but I get a type mismatch error.
Feeling slightly dumb and overly tired here, so maybe someone can give me some advice on how to proceed.
TiA
Markus
This is a pure A array, so you need a:
Dim myAarray() as cClassA = response.ClassAarray
This is a “down cast” - trying to make all the supers into one of their subclass which wont work
While every instance of cClassAB ISA ClassA (subclasses are always instances of the super) the reverse is not true; every ClassA is NOT a cClassAB
But thats what you would need
(ie/ every domestic dog is a canid but not every canid is a domestic dog)
Module ClassAExtension
Global Function B(Extends sender As ClassA) As Integer
Return sender.A() + 10
End Function
End Module
Let’s suppose ClassA have just a method A() that returns an integer, and you wanted to add a new method B() that returns A+10. You could just extend the class with a helper module with a global method extension for such class like the above. It’ll enable you do things like:
Dim ab As new ClassA
MsgBox ab.B.ToText // The B() method does not exist IN the class, but works