Solved

Objects - How to add additional property in Class

Posted on 2010-09-03
5
235 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 17

Expert Comment

by:Zhaolai
ID: 33597406
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
ID: 33597941
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
ID: 33597987
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
ID: 33598024
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
ID: 33602367
Great solution, thanks
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

617 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