I have a object type variable (control .Tag) that I need to cast to a structured type, and change a member in. This is a contrived but representative example:
Public Structure struct_COLOURS
Dim ILikeRed as boolean
Dim ILikeGreen as boolean
End Structure
Dim AnObject as Object = (some source that is struct_COLOURS)
DirectCast(AnObject, struct_COLOURS).ILikeRed = True ' This is not valid syntax?!
I don't remember my C syntax very well, but it would be something like this:
(struct_COLOURS*)AnObject->ILikeRed = true;
The point is I can cast an object to something and set members in the resulting cast. It seems as though DirectCast is actually a function and is not casting in the way I would interpret it.
Oddly, if you only want to retrieve a member value, you can use DirectCast:
dim YummyRed AS Boolean = DirectCast(AnObject, struct_COLOURS).ILikeRed
is just fine!
If I cannot cast the way I want, and I cannot change the use of the Tag property (so please don't suggest, it's not an option) to store these structures, what is the fastest way to set members?