Link to home
Create AccountLog in
Avatar of TeDeSm
TeDeSm

asked on

Objects - How to add additional property in Class

I have the following code for a Customer object and would like to add additional properties. In this instance I would like to add IDCustomer. There is only one ID per customer. What would be the correct syntax for this?

I currently fill an array with customerArray.Add(New Customer(reader1("CompanyName"))).
Public Class Customer
	Inherits [Object]
	Private custID As Long
	Private custName As String = ""
	Friend custOrders As New ArrayList()

	Public Sub New(ByVal customername As String)
		Me.custName = customername
	End Sub

	Public Property CustomerName() As String
		Get
			Return Me.custName
		End Get
		Set(ByVal Value As String)
			Me.custName = Value
		End Set
	End Property

	Public ReadOnly Property CustomerOrders() As ArrayList
		Get
			Return Me.custOrders
		End Get
	End Property
End Class 'End Customer class


Public Class Order
	Inherits [Object]
	Private ordID As String

	Public Sub New(ByVal orderid As String)
		Me.ordID = orderid
	End Sub 'New

	Public Property OrderID() As String
		Get
			Return Me.ordID
		End Get
		Set(ByVal Value As String)
			Me.ordID = Value
		End Set
	End Property
End Class ' End Order class

Open in new window

Avatar of Zhaolai
Zhaolai
Flag of United States of America image

Add this code to your class:


	Public Property CustomerID() As Long
		Get
			Return Me.custID
		End Get
		Set(ByVal Value As Long)
			Me.custID = Value
		End Set
	End Property

Open in new window

Avatar of TeDeSm
TeDeSm

ASKER

Thanks for the help.

I am specifying my array Private customerArray As New ArrayList() and filling it with
 customerArray.Add(New Customer(reader1("CompanyName")))

I need this array to hold IDCustomer as well as the CustomerName, how do I set both for each array entry?
Dim cust as New Customer(reader1("CompanyName"))
cust.CustomerID =reader1("CustomerID")
customerArray.Add(cust)

ASKER CERTIFIED SOLUTION
Avatar of Zhaolai
Zhaolai
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of TeDeSm

ASKER

Great solution, thanks