A VB Class is not a whole lot different to a Java class. It needs to be defined within a class module, and is simply a collection of hidden variables that are accessed via 'Property Let' and 'Property Get' statements - So, say I want to create a class that represents a Cartesian Coordinate called CartCoord, I'd create a class module Called CartCoord and fill it with the following:
Code:
Private privX as Double
Private privY as Double
Property Let X (aValue as Double)
privX = aValue
End Property
Property Get X () as Double
X = privX
End Property
Property Let Y (aValue as Double)
privY = aValue
End Property
Property Get Y () as Double
Y = privY
End Property
Property Get DistanceFromOrigin() as Double
DistanceFromOrigin = Sqr(PrivX^2 + PrivY^2)
End Function
So after creating an instance of the object, I can populate the X and Y values, and then ask it to tell me the distance the represented point is from the Origin like so:
Code:
Set MyPoint = New CartCoord
MyPoint.X = 3
MyPoint.Y = 4
Z = MyPoint.DistanceFromOrigin
So later, when I query Z (assuming I remember my trigonometry right), I should have a value of 5.