|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Define an object???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. A structure, as opposed to a class, may be another option for this.
Show quoteHide quote "Charlie Brown" <cbr***@duclaw.com> wrote in message news:1149538653.879971.288700@j55g2000cwa.googlegroups.com... > 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 Show quoteHide quote "Mike Lowery" <selfspam@mouse-potato.com> schrieb im Newsbeitrag news:eenvqiOiGHA.4304@TK2MSFTNGP03.phx.gbl... >A structure, as opposed to a class, may be another option for this. > > "Charlie Brown" <cbr***@duclaw.com> wrote in message > news:1149538653.879971.288700@j55g2000cwa.googlegroups.com... >> 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. >> > >
http://www.informit.com/articles/article.asp?p=25864&rl=1
Show quote Hide quote "Jerry" <jerry***@gmx.net> wrote in message
news:e64lka$hpi$00$1@news.t-online.com... > 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@mouse-potato.com> schrieb im Newsbeitrag > news:eenvqiOiGHA.4304@TK2MSFTNGP03.phx.gbl... >>A structure, as opposed to a class, may be another option for this. >> >> "Charlie Brown" <cbr***@duclaw.com> wrote in message >> news:1149538653.879971.288700@j55g2000cwa.googlegroups.com... >>> 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. >>> >> >> > >
Close form if no user action including mouse move over form.
Can't create AutoFiltered Excel worksheet using VB.NET Accessing inherited variables Textbox Lines Limit Use a System.Type in Generics? Newbie needs help with datagrid Read value of all columns from datatable together Generate Microsoft Office Document? CreateObject error Need to start word 2003 and show existing rtf doc in VB.Net |
|||||||||||||||||||||||