Solved

Objects - How to add additional property in Class

Posted on 2010-09-03
5
230 Views
Last Modified: 2013-11-27
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

0
Comment
Question by:TeDeSm
  • 3
  • 2
5 Comments
 
LVL 17

Expert Comment

by:Zhaolai
Comment Utility
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

0
 

Author Comment

by:TeDeSm
Comment Utility
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?
0
 
LVL 17

Expert Comment

by:Zhaolai
Comment Utility
Dim cust as New Customer(reader1("CompanyName"))
cust.CustomerID =reader1("CustomerID")
customerArray.Add(cust)

0
 
LVL 17

Accepted Solution

by:
Zhaolai earned 500 total points
Comment Utility
Or you can change sub New in your Customer class like this:

      Public Sub New(ByVal CustomerID as Long,  ByVal customername As String)
            me.custID = CustomerID
Me.custName = customername
      End Sub

Then when you add to arraylist, do this:
customerArray.Add(New Customer(reader1("CustomerID"), reader1("CompanyName")))
0
 

Author Closing Comment

by:TeDeSm
Comment Utility
Great solution, thanks
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now