Sorry that this turned into a long rant. Maybe someone will find it interesting enough to make it all the way through and comment.
I've been programming VB for quite a while but have managed for the mostpart to avoid using classes. On my latest project I decided to bite the bullet and go totally OOP. The result? Frustration.
My object is essentially a rectangle defined by the cartesian coordinates of its corners. The user will be able to place the rectangles in a real-world coordinate system using data from a survey (I'm a surveyor). Seems easy enough, right?
So the first thing I do is create a user defined type (UDT) for a cartesian point:
But it seems that I can't pass a UDT to my object. Why not? Okay, well I'll make a cartesian point object and pass that:
Okay, now I can pass my point object to my rectangle class, which will contain an array of four points. Life is good, right? Not quite.
I need to parse an ascii file for points. So I'll just do what I always do - write a function:
Well, VB doesn't seem to like that. It seems that functions can't return classes. So I'm left making a new method in my simple point2d class:
All this to try to mimic the functionality of a UDT. What a waste. All this and I haven't even gotten to create the class that I really care about (the rectangle).
Should I go back to writing my non-OOP code? I can't seem to get my head around VB's logic here. Do people really jump through all these hoops in order to work with classes? What am I missing?
I've been programming VB for quite a while but have managed for the mostpart to avoid using classes. On my latest project I decided to bite the bullet and go totally OOP. The result? Frustration.
My object is essentially a rectangle defined by the cartesian coordinates of its corners. The user will be able to place the rectangles in a real-world coordinate system using data from a survey (I'm a surveyor). Seems easy enough, right?
So the first thing I do is create a user defined type (UDT) for a cartesian point:
Code:
'IN A REGULAR MODULE
Type point2d
X As Double
Y As Double
ptname as string
End Type
But it seems that I can't pass a UDT to my object. Why not? Okay, well I'll make a cartesian point object and pass that:
Code:
'IN MY POINT2D CLASS MODULE
Private Type point2d
X As Double
Y As Double
ptname as string
End Type
Private objPoint2d As point2d
Public Property Let X(X As Double)
objPoint2d.X = X
End Property
'and so on for 'Y' and 'ptname'
Okay, now I can pass my point object to my rectangle class, which will contain an array of four points. Life is good, right? Not quite.
I need to parse an ascii file for points. So I'll just do what I always do - write a function:
Code:
'IN A FORM
private function Ascii2Pt (instrin as string) as point2d
'do stuff here
end function
Well, VB doesn't seem to like that. It seems that functions can't return classes. So I'm left making a new method in my simple point2d class:
Code:
'BACK TO THE DANG CLASS MODULE
Public Property Let AsciiToPoint(mystring As String)
'Do some more stuff
End Property
All this to try to mimic the functionality of a UDT. What a waste. All this and I haven't even gotten to create the class that I really care about (the rectangle).
Should I go back to writing my non-OOP code? I can't seem to get my head around VB's logic here. Do people really jump through all these hoops in order to work with classes? What am I missing?