Link to home
Start Free TrialLog in
Avatar of TeDeSm
TeDeSm

asked on

VB.Net How to refer to elements in an array list

I require the correct syntax to enable me retrieve values of elements from an ArrayList.

The ArrayList is a list of Customer objects each of which has IDCustomer, CustomerName and CustomerOrders.

In the forms class I use
Public Class frmPreAlert
  ' Create a new ArrayList to hold the Customer objects.
  Private customerArray As New ArrayList()

I fill the Customer array with:

' Get Customer references
   reader1 = cmd1.ExecuteReader()
   While reader1.Read()
       lngIDCompany = reader1("IDCompany")
       strCompanyName = reader1("CompanyName")
      customerArray.Add(New Customer(reader1("IDCompany"), reader1("CompanyName")))
   End While

Later in the sub I want to read the contents of customerArray by For Each loop:
' Add IDPreAlerts to each Order in Customer object in the ArrayList.
   Dim customer1 As Customer
   For Each customer1 In customerArray

      lngIDCompany = *** This is where I need the value of IDCustomer ***
                     <snip>
   Next customer1

Just can't get on with VS2010 help.
' Customer CLASS

Public Class Customer Inherits [Object]
    Private idComp As Long
    Private custName As String = ""
    Friend custOrders As New ArrayList()

Public Sub New(ByVal idcompany As Long, ByVal customername As String)
        Me.idComp = idcompany
        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 Property CustomerID() As Long
        Get
            Return Me.idComp
        End Get
        Set(ByVal Value As Long)
            Me.idComp = 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

ASKER CERTIFIED SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TeDeSm
TeDeSm

ASKER

Thanks for your help. I do have some renaming to do as the code is being re-used from elsewhere.