Define an object???

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jerry

    #1

    Define an object???

    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.di ameter.color.fa ctor

    How would one define these shafts and retrieve the information?

    Thanks,

    Jerry


  • Charlie Brown

    #2
    Re: Define an object???

    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.

    Comment

    • Mike Lowery

      #3
      Re: Define an object???

      A structure, as opposed to a class, may be another option for this.

      "Charlie Brown" <cbrown@duclaw. com> wrote in message
      news:1149538653 .879971.288700@ j55g2000cwa.goo glegroups.com.. .[color=blue]
      > 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.
      >[/color]


      Comment

      • Jerry

        #4
        Re: Define an object???

        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




        "Mike Lowery" <selfspam@mou se-potato.com> schrieb im Newsbeitrag
        news:eenvqiOiGH A.4304@TK2MSFTN GP03.phx.gbl...[color=blue]
        >A structure, as opposed to a class, may be another option for this.
        >
        > "Charlie Brown" <cbrown@duclaw. com> wrote in message
        > news:1149538653 .879971.288700@ j55g2000cwa.goo glegroups.com.. .[color=green]
        >> 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.
        >>[/color]
        >
        >[/color]


        Comment

        • Mike Lowery

          #5
          Re: Define an object???



          "Jerry" <jerryleo@gmx.n et> wrote in message
          news:e64lka$hpi $00$1@news.t-online.com...[color=blue]
          > 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
          >
          >
          >
          >
          > "Mike Lowery" <selfspam@mou se-potato.com> schrieb im Newsbeitrag
          > news:eenvqiOiGH A.4304@TK2MSFTN GP03.phx.gbl...[color=green]
          >>A structure, as opposed to a class, may be another option for this.
          >>
          >> "Charlie Brown" <cbrown@duclaw. com> wrote in message
          >> news:1149538653 .879971.288700@ j55g2000cwa.goo glegroups.com.. .[color=darkred]
          >>> 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.
          >>>[/color]
          >>
          >>[/color]
          >
          >[/color]


          Comment

          Working...