Trouble! Array of Array of UDT
Hey all
Im having trouble defining an array of an array of user defined types.
So far i have:
VB Code:
Public Type POINTAPI
X As Long
Y As Long
End Type
Public Points() As POINTAPI
Public Objects() As Variant
VB Code:
Private Sub Form_Load()
Objects = Array()
ReDim Points(0) As POINTAPI
ReDim Objects(0) As Variant
End Sub
VB Code:
Private Sub cmdcomplete_Click()
Objects(UBound(Objects)) = Points
ReDim Objects(UBound(Objects) + 1)
Erase Points
ReDim Points(0)
Basicly points is an array of coords that defines a polygon. When cmdcomplete is clicked this polygon is added to the objects array, and the points array initialized to create another polygon ;d
Thanks for any help
/edit, compiler doesn't like line: Objects(UBound(Objects)) = Points
Stating: Only UDT defined in public object modules can be coerced to or from a variant.
Re: Trouble! Array of Array of UDT
Try and have instead of Variants
Re: Trouble! Array of Array of UDT
Hey thanks for the reply.
I get a type mismatch error on the same line as before doing it your way :(!
Re: Trouble! Array of Array of UDT
Sorry for bumping but really need help with this!!
Seems such a trivial thing to do i don't understand why it isn't so simple :(
Re: Trouble! Array of Array of UDT
How about this way
VB Code:
objects(UBound(objects)) = points(UBound(points))
Re: Trouble! Array of Array of UDT
That would put the last element of the points array in objects which isn't my aim. I want to put the whole array points in an element of objects.
Re: Trouble! Array of Array of UDT
To get around the Only UDT defined in public object modules... error you can create a dummy class that contains Public variables x and y and use it instead of the UDT.
Re: Trouble! Array of Array of UDT
Yes after some research i realised that is my only option. Which is a mighty kick in the crutch, as i need to pass the points to API's like polygon which require a UDT so i presume i need to convert them from dummy classes and back again every time i require these apis, which is very inefficient and nasty!!!!
Re: Trouble! Array of Array of UDT
After the UDT has the data wouldn't all you need do is the following?
MyClass.x = Point.x
MyClass.y = Point.y
Re: Trouble! Array of Array of UDT
but everytime my image refreshs i will have to pull all data out of the dummy classes back into udts to pass to polygon api's, just annoying is all.
:(