Define an object???

  • Thread starter Thread starter Jerry
  • Start date Start date
J

Jerry

Hello,

I'm working my way through "Visual Basic 2003 in so and so many days".
At the same time I'm trying to create a windows application and I'm a little
impatient.

I have the folowing problem:
I have different shafts that consist of a diameter, a color, a lenght, and a
factor.
I'd like to define the shafts so that I can identify them by inputing the
diameter and the color.
So dia. 2" and color green would give me lenth 12" and factor 4. I have
about 50 dia. and 3 colors
and the according lenght nd factor.

I was thinking about something like

lenght = shaft.diameter.color.lenght
factor=shaft.diameter.color.factor

How would one define these shafts and retrieve the information?

Thanks,

Jerry
 
You would need to create new classes to represent the shafts as
objects. Sounds like you could create one class and then call a new
instance of that class for each diff type of object. There is a lot
that can be done with this but here is a start..

Public Class Shaft

Private _diameter As Decimal
Private _color As String
Private _length As Decimal
Private _factor As Decimal

Public Property Diameter() As Decimal
Get
Return _diameter
End Get
Set(ByVal Value As Decimal)
_diameter = Value
End Set
End Property

'do this for each Property you want to access

Public Sub New(ByVal diameter As Decimal, ByVal color As String, ByVal
length As Decimal, ByVal factor As Decimal)
_diameter = diameter
_color = color
_length = length
_factor = factor
End Sub

End Class

Then in your application create an instance of the shaft like this...

Dim objShaft As New Shaft(2, "Green", 12, 4)

access the properties of your object like so...

mylength = objShaft.Length

This is only a start and a very basic example, but something you can
work with.
 
Thanks Charlie,

I'll try this out. I did think it was possible to put them all in one I
guess class.
I just don't know how.

Mike, what is a structure?


Thanks,

Jerry
 
Back
Top