473,394 Members | 1,709 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,394 software developers and data experts.

Using LastIndexOf w/ Structure Stored in ArrayList

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?
Expand|Select|Wrap|Line Numbers
  1. Public Overrides Function Equals(ByVal obj As Object) As Boolean
  2.   If TypeOf obj Is duplicates Then
  3.     If account = CType(obj, duplicates).account Then
  4.       Return True
  5.     Else
  6.       Return False
  7.     End If
  8.   End If
  9. End Function
  10.  
  11. Public Overloads Function Equals(ByVal obj1 As Object, ByVal obj2 As Object) As Boolean
  12.   If TypeOf obj1 Is duplicates AndAlso TypeOf obj2 Is duplicates Then
  13.     If CType(obj1, duplicates).account = CType(obj2, duplicates).account Then
  14.       Return True
  15.     Else
  16.       Return False
  17.     End If
  18.   End If
  19. End Function
  20.  
  21. Dim arrResults As New ArrayList 
  22. Dim dupEntries As New duplicates 
  23.  
  24. While reader.Read 
  25.   With arrResults 
  26.     .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)))
  27.   End With 
  28. End While 
  29. reader.Close()
  30.  
  31. Dim first As duplicates 
  32. Dim last As duplicates 
  33. Dim i As Integer 
  34.  
  35. For i = 0 To arrResults.Count - 1 
  36.   first = CType(arrResults.Item(i), duplicates) 
  37.   Trace.Warn(arrResults.LastIndexOf(first.account))
  38.   last = arrResults.Item(arrResults.LastIndexOf(first.account))
  39.   Trace.Warn("first date" & first.tDate) 
  40.   Trace.Warn("last date " & last.tDate) 
  41. Next 
  42.  
Oct 26 '06 #1
0 1399

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Douglas Buchanan | last post by:
Newbie to donnet This is an example of a structure given in vs.net help ============================ Private Structure Employee Public GivenName As String ' This employee's given name....
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
0
by: Patrick.O.Ige | last post by:
I have a datagrid with checkboxes.. When a user clicks one check box and clicks the delete button it deletes that ROw. There another situation when a user clicks multiple rows so i had to loop...
7
by: Adam | last post by:
Hi all, In my VB.NET code below, I try to change the user name in my arraylist from Ted to Bob, but instead it adds a new user to the arraylist named Bob. Can anyone explain why this happens and...
7
by: pmclinn | last post by:
I was wondering if it is possible to dynamically create a structure. Something like this: public sub main sql = "Select Col1, Col2 from Table a" dim al as new arraylist al =...
6
by: mm | last post by:
Hi All, I am a newbie in Vb.net and I have some problems I have a structure called padrecord. In this structure i have X,Y len h w name typeval First I add the known values in X and Y. And put...
0
by: ccshine via DotNetMonster.com | last post by:
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...
0
by: Eugene Anthony | last post by:
The problem with my coding is that despite removing the records stored in the array list, the rptPages repeater control is still visible. The rptPages repeater control displayes the navigation...
1
by: =?Utf-8?B?SmF5Qw==?= | last post by:
I am trying to understand how to use an arraylist that contains data in a structure and bind the results to a gridview. Using vs2008 I have looked at the examples 315784 HOW TO: Bind a DataGrid...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.