ArrayList and Object Retrieval
I am using the following code to load an ArrayList with an object.
HTML Code:
Do While Not EOF(jjFileNumber)
Dim omdObj As New OMD
Dim omdText As String = LineInput(jjFileNumber)
Dim omdValue() As String = Split(omdText, ",")
Dim value As String = String.Empty
'Serial number is in b (index 1)
value = omdValue(1)
omdObj.SerialNumber = value
'EQ ID is in column C or index 2
omdObj.EquipID = omdValue(2)
'Maint Type is in Column D or index 3
omdObj.MaintType = omdValue(3)
'System Model is in Column E or index 4
omdObj.sysModel = omdValue(4)
'System Serial is in Column F or index 5
omdObj.sysSerial = omdValue(5)
'Customer ShipTo is in column I or index 8
omdObj.custShipToAcct = omdValue(8)
'customer name is in column J or index 9
omdObj.CustomerName = omdValue(9)
OMDlist.Add(omdObj)
Loop
FileClose(jjFileNumber)
End If
It works great~! However,
I don't know how to retrieve the object from the ArrayList using the Item property.
I am using the following withOUT Success. The code is searching the arraylist for a match on serial number. Values(2) is correct and is working fine - the problem is purely getting the object information from the arraylist.
Code:
For ctr = 0 To OMDlist.Count - 1
If Values(2) = OMDList.Item(ctr) Then
ps.AssetNbr = OMDlist.Item(ctr)
End If
Next
the object has the following property structure:
Code:
Public Class OMD
Private strSN As String
Private strEQID As String
Private strCustName As String
Private strCustAcct As String
Private strSysMod As String
Private strSysSerial As String
Private strMaintType As String
Property SerialNumber() As String
Get
Return strSN
End Get
Set(ByVal Value As String)
strSN = Value
End Set
End Property
Property EquipID() As String
Get
Return strEQID
End Get
Set(ByVal Value As String)
strEQID = Value
End Set
End Property
Property CustomerName() As String
Get
Return strCustName
End Get
Set(ByVal Value As String)
strCustName = Value
End Set
End Property
Property custShipToAcct() As String
Get
Return strCustAcct
End Get
Set(ByVal Value As String)
strCustAcct = Value
End Set
End Property
Property MaintType() As String
Get
Return strMaintType
End Get
Set(ByVal Value As String)
strMaintType = Value
End Set
End Property
Property sysModel() As String
Get
Return strSysMod
End Get
Set(ByVal Value As String)
strSysMod = Value
End Set
End Property
Property sysSerial() As String
Get
Return strSysSerial
End Get
Set(ByVal Value As String)
strSysSerial = Value
End Set
End Property
End Class
How do I pull the propertys back from the object in the arraylist to compare the values with Values(2)?
Thank you in advance for any help you can provide. It is greatly appreciate.
Re: ArrayList and Object Retrieval
You'll need a DirectCast TryCast or CType function.
But!
If you use Generic collection (see Generic Types) instead of old (and obsolete) ArrayList, you won't need to convert the types at all.
Code:
Dim OMDList As New List(Of OMD)
Also, you could read more about searilization of classes and using XML.
Re: ArrayList and Object Retrieval
A little more to the point (but the suggestion that you use List(Of T) is a good idea...)
The reason is because OMDlist.Item(ctr) IS your OBJECT... NOT your property...]
You need to compare your value against the value of the PROPERTY you want to look at:
Code:
If Values(2) = OMDlist.Item(ctr).SerialNumber then
-tg