DrEvilBeer
02-11-2004, 01:54 PM
I'm trying to create a custom collection class that will aloow me to implement it in the following fashion...
-
Dim SalesTRX As New SalesTransaction
SalesTRX.LineItems.Add("12345", "Item 12345 - Random Widget")
SalesTRX.LineItems.Add("12346", "Item 12346 - Random Widget #2")
Console.WriteLine(SalesTRX.LineItems(0).ItemNumber) 'Would return "12345" as string
SalesTRX.LineItems(0).ItemNumber = "54321" 'Would change value from 12345 to 54321
-
Below is the code I have so far, but obviously there's something I'm missing... I just couldn't wrap my mind around what to do next.
I have two classes, "SalesTransaction" and "LineItemCollection".
The LineItemCollection class is used in SalesTransaction and LineItem structure objects should be members of the LineItemCollection. LineItem objects should be created when the Add method of LineItemCollection is invoked and should be able to be read and written to from the "Item" property in LineItemCollection. If someone could point me in the right direction it would be of great help to me. Thanks!
--------
Public Class SalesTransaction
Private collectionLineItem As LineItemCollection
Public Property LineItems(ByVal lineNumber As Integer) As LineItemCollection
Get
Return Me.collectionLineItem(lineNumber)
End Get
Set(ByVal Value As LineItemCollection)
Me.collectionLineItem(lineNumber) = Value
End Set
End Property
End Class
Public Class LineItemCollection
Private itemLine As LineItem
Default Public Property Item(ByVal lineNumber As Integer) As LineItem
Get
Return 'Me.itemLine(lineNumber)
End Get
Set(ByVal Value As LineItem)
'Me.itemLine(lineNumber) = Value
End Set
End Property
Sub Add(ByVal itemNumber, ByVal itemName)
'Add line item object to LineItemCollection
End Sub
Sub Remove(ByVal itemNumber)
'Remove item from collection by item number
End Sub
End Class
Public Structure LineItem
Private m_ItemNumber As String
Private m_ItemName As String
Public Property ItemNumber() As String
Get
Return Me.m_ItemNumber
End Get
Set(ByVal Value As String)
m_ItemNumber = Value
End Set
End Property
Public Property ItemName() As String
Get
Return Me.m_ItemName
End Get
Set(ByVal Value As String)
m_ItemName = Value
End Set
End Property
End Structure
-
Dim SalesTRX As New SalesTransaction
SalesTRX.LineItems.Add("12345", "Item 12345 - Random Widget")
SalesTRX.LineItems.Add("12346", "Item 12346 - Random Widget #2")
Console.WriteLine(SalesTRX.LineItems(0).ItemNumber) 'Would return "12345" as string
SalesTRX.LineItems(0).ItemNumber = "54321" 'Would change value from 12345 to 54321
-
Below is the code I have so far, but obviously there's something I'm missing... I just couldn't wrap my mind around what to do next.
I have two classes, "SalesTransaction" and "LineItemCollection".
The LineItemCollection class is used in SalesTransaction and LineItem structure objects should be members of the LineItemCollection. LineItem objects should be created when the Add method of LineItemCollection is invoked and should be able to be read and written to from the "Item" property in LineItemCollection. If someone could point me in the right direction it would be of great help to me. Thanks!
--------
Public Class SalesTransaction
Private collectionLineItem As LineItemCollection
Public Property LineItems(ByVal lineNumber As Integer) As LineItemCollection
Get
Return Me.collectionLineItem(lineNumber)
End Get
Set(ByVal Value As LineItemCollection)
Me.collectionLineItem(lineNumber) = Value
End Set
End Property
End Class
Public Class LineItemCollection
Private itemLine As LineItem
Default Public Property Item(ByVal lineNumber As Integer) As LineItem
Get
Return 'Me.itemLine(lineNumber)
End Get
Set(ByVal Value As LineItem)
'Me.itemLine(lineNumber) = Value
End Set
End Property
Sub Add(ByVal itemNumber, ByVal itemName)
'Add line item object to LineItemCollection
End Sub
Sub Remove(ByVal itemNumber)
'Remove item from collection by item number
End Sub
End Class
Public Structure LineItem
Private m_ItemNumber As String
Private m_ItemName As String
Public Property ItemNumber() As String
Get
Return Me.m_ItemNumber
End Get
Set(ByVal Value As String)
m_ItemNumber = Value
End Set
End Property
Public Property ItemName() As String
Get
Return Me.m_ItemName
End Get
Set(ByVal Value As String)
m_ItemName = Value
End Set
End Property
End Structure