ArrayList. I used this setup to bind to a DataGrid and it worked out so well,
I thought it might be a better solution that moving back and forth through a
DataSet to perform some simple though numerous calculations.
In order to perform these calcs, I have to compare elements of the array
checking for duplicates on some columns and then just comparing others to
strings utilizing IndexOf and LastIndexOf. Unfortunately I haven't been able
to get it to work. On another site I read that these 2 methods use Object.
Equals and as the array contains structure objects regardless of whether the
values appear to be equal or not, both methods will always return -1. It
also stated that the Equals function needs to be overridden. I tried this
as well with no luck.
The code below generates an index is out of range error on the line that
assigns the array item to 'last' because the LastIndexOf search returns -1.
Also noteworthy is that the stored procedure I use to retrieve the recordset
guarantees that there would be a match on first.account. Can anyone point me
in the right direction?
Expand|Select|Wrap|Line Numbers
- Public Overrides Function Equals(ByVal obj As Object) As Boolean
- If TypeOf obj Is duplicates Then
- If account = CType(obj, duplicates).account Then
- Return True
- Else
- Return False
- End If
- End If
- End Function
- Public Overloads Function Equals(ByVal obj1 As Object, ByVal obj2 As Object) As Boolean
- If TypeOf obj1 Is duplicates AndAlso TypeOf obj2 Is duplicates Then
- If CType(obj1, duplicates).account = CType(obj2, duplicates).account Then
- Return True
- Else
- Return False
- End If
- End If
- End Function
- Dim arrResults As New ArrayList
- Dim dupEntries As New duplicates
- While reader.Read
- With arrResults
- .Add(New duplicates(reader.GetValue(0), reader.GetValue(1), reader.GetValue(2), reader.GetValue(3), reader.GetValue(4), reader.GetValue(5), reader.GetValue(6), reader.GetValue(7), reader.GetValue(8), reader.GetValue(9), reader.GetValue(10), reader.GetValue(11), reader.GetValue(12), reader.GetValue(13), reader.GetValue(14)))
- End With
- End While
- reader.Close()
- Dim first As duplicates
- Dim last As duplicates
- Dim i As Integer
- For i = 0 To arrResults.Count - 1
- first = CType(arrResults.Item(i), duplicates)
- Trace.Warn(arrResults.LastIndexOf(first.account))
- last = arrResults.Item(arrResults.LastIndexOf(first.account))
- Trace.Warn("first date" & first.tDate)
- Trace.Warn("last date " & last.tDate)
- Next