B
Big Charles
Hello,
I would like to create an array-class to be able to call like:
Dim oMyCar as New MyCar
' After initializing oMyCar, the object has to be like:
oMyCar(0).Brand
oMyCar(0).Wheels.NumberOfWheels
oMyCar(0).Wheels.ColorOfWheels
oMyCar(1).Brand
oMyCar(1).Wheels.NumberOfWheels
oMyCar(1).Wheels.ColorOfWheels
The object has to be an array list itself with properties like Brand
and sub-objects like Wheels.
I think I should create the class like this:
Public Class MyCar
Inherits CollectionBase
Public Wheels As MyWheels
Private mBrand As String
Public Sub New()
Get_Data()
End Sub
Private Function Get_Data()
' DataReader dr has been populated
If dr.HasRows Then
While dr.Read
' I am not sure how to create the array object from here
Me.Add()
mBrand = dr.Item("Brand").ToString()
End While
Wheels = New MyWheels(mBrand)
End If
dr.Close()
End Function
Sub Add(ByVal il As Object)
Me.List.Add(il)
End Sub
Public Property Brand() As String
Get
Return mDescripcion
End Get
Set(ByVal Value As String)
mDescripcion = Value
End Set
End Property
End Class
I would like to create an array-class to be able to call like:
Dim oMyCar as New MyCar
' After initializing oMyCar, the object has to be like:
oMyCar(0).Brand
oMyCar(0).Wheels.NumberOfWheels
oMyCar(0).Wheels.ColorOfWheels
oMyCar(1).Brand
oMyCar(1).Wheels.NumberOfWheels
oMyCar(1).Wheels.ColorOfWheels
The object has to be an array list itself with properties like Brand
and sub-objects like Wheels.
I think I should create the class like this:
Public Class MyCar
Inherits CollectionBase
Public Wheels As MyWheels
Private mBrand As String
Public Sub New()
Get_Data()
End Sub
Private Function Get_Data()
' DataReader dr has been populated
If dr.HasRows Then
While dr.Read
' I am not sure how to create the array object from here
Me.Add()
mBrand = dr.Item("Brand").ToString()
End While
Wheels = New MyWheels(mBrand)
End If
dr.Close()
End Function
Sub Add(ByVal il As Object)
Me.List.Add(il)
End Sub
Public Property Brand() As String
Get
Return mDescripcion
End Get
Set(ByVal Value As String)
mDescripcion = Value
End Set
End Property
End Class