473,395 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Comparing Structure Objects w/ LastIndexOf

I'm working on an app that implements a Structure to store a recordset in an
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?
Public Overrides Function Equals(ByVal obj As Object) As Boolean

If obj Is Nothing Or Not Me.GetType() Is obj.GetType() Then

Return False

End If

Dim d As duplicates = CType(obj, duplicates)

Return Me.account = d.account

End Function
'Errant code below

conn.Open()
Dim reader As SqlDataReader = cmd.ExecuteReader()

If reader.HasRows Then

'Create array to hold entries for accounts tracked more than once per LOB

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.accou nt))

Trace.Warn(

"first date" & first.tDate)
Trace.Warn(

"last date " & last.tDate)

Next

End If

--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...p-net/200610/1

Oct 26 '06 #1
0 1152

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Stephen | last post by:
I have to write a .Net application which can compare SQL Databases including things like: - DB structure, PK's, FK's, indexes and types of indexes i.e. should be able to detect if the same index...
19
by: Dennis | last post by:
I have a public variable in a class of type color declared as follows: public mycolor as color = color.Empty I want to check to see if the user has specified a color like; if mycolor =...
3
by: Mark Denardo | last post by:
Hi I have an app that has a number of textboxes (richtextboxes to be exact) that get created dynamically and I add a few at a time to panel controls (so I can flip a group in and out when I want). ...
7
by: andreas | last post by:
Hello, I have a problem with iterators in a fairly complex polygonal mesh data structure which is implemented using lists of geometric entities. However, the problem in itself is fairly simple:...
12
by: barcaroller | last post by:
Is it legal to compare the contents of two multi-field variables (of the same struct) using "==" and "!="? struct { int a; int b; } x,y; ...
19
by: Ole Nielsby | last post by:
How does the GetHashCode() of an array object behave? Does it combine the GetHashCode() of its elements, or does it create a sync block for the object? I want to use readonly arrays as...
9
by: senfo | last post by:
I realize it's Friday and I'm probably already on vacation for the remainder of the day; but, I have a really, really stupid question. Is there a bug in the .NET 2.0 Framework in regards to the...
25
by: J Caesar | last post by:
In C you can compare two pointers, p<q, as long as they come from the same array or the same malloc()ated block. Otherwise you can't. What I'd like to do is write a function int comparable(void...
22
RamananKalirajan
by: RamananKalirajan | last post by:
Hello I am working on WorkBreak Down structures, but i was unable to finish it perfectly. I am posting my code with this. I have to finish this task. please help me out. It must form like this ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.