473,325 Members | 2,785 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,325 software developers and data experts.

Finding Dupe in a List

I have a function which return a List, and I'm trying to add users to
it from 3 different roles, but I don't want duplicate user names. The
"Contains" ALWAYS is returning FALSE, so I'm not finding the dupe.
Here's the code:

Dim datalist As New List(Of TroubleTicketUser)
Dim str As String
Dim theroles(2) As String, therole As String

theroles(0) = "IT User"
theroles(1) = "IT Admin"
theroles(2) = "Customer Service Rep"

For Each therole In theroles
For Each str In Roles.GetUsersInRole(therole)
Dim tt As New TroubleTicketUser(str)
If Not datalist.Contains(tt) Then datalist.Add(tt)
Next
Next

datalist.Sort()

Return datalist

---------------------
Why doesn't the Contains work?

Jul 30 '07 #1
4 1465
On 30 juil, 15:26, Larry Bud <larrybud2...@yahoo.comwrote:
I have a function which return a List, and I'm trying to add users to
it from 3 different roles, but I don't want duplicate user names. The
"Contains" ALWAYS is returning FALSE, so I'm not finding the dupe.
Here's the code:

Dim datalist As New List(Of TroubleTicketUser)
Dim str As String
Dim theroles(2) As String, therole As String

theroles(0) = "IT User"
theroles(1) = "IT Admin"
theroles(2) = "Customer Service Rep"

For Each therole In theroles
For Each str In Roles.GetUsersInRole(therole)
Dim tt As New TroubleTicketUser(str)
If Not datalist.Contains(tt) Then datalist.Add(tt)
Next
Next

datalist.Sort()

Return datalist

---------------------
Why doesn't the Contains work?
Hi,
Check out this link : http://expressdotnet.freehostia.com
Omar Abid

Jul 30 '07 #2
Larry Bud wrote:
I have a function which return a List, and I'm trying to add users to
it from 3 different roles, but I don't want duplicate user names. The
"Contains" ALWAYS is returning FALSE, so I'm not finding the dupe.
Here's the code:

Dim datalist As New List(Of TroubleTicketUser)
Dim str As String
Dim theroles(2) As String, therole As String

theroles(0) = "IT User"
theroles(1) = "IT Admin"
theroles(2) = "Customer Service Rep"

For Each therole In theroles
For Each str In Roles.GetUsersInRole(therole)
Dim tt As New TroubleTicketUser(str)
If Not datalist.Contains(tt) Then datalist.Add(tt)
Next
Next

datalist.Sort()

Return datalist

---------------------
Why doesn't the Contains work?
The Contains method works just fine, it just doesn't work the way that
you expected it to work.

The Contains method, when used on a List of reference types, checks if a
reference to the object exists in the list. As you create a new instance
of the TroubleTicketUser class, it's not the same object as the one that
exists in the list, eventhough they contain the same data.

What you want to do is to use a Dictionary(Of String, TroubleTicketUser)
where you use the user name as key.

--
Göran Andersson
_____
http://www.guffa.com
Jul 31 '07 #3
On Jul 31, 5:56 am, Göran Andersson <gu...@guffa.comwrote:
Larry Bud wrote:
I have a function which return a List, and I'm trying to add users to
it from 3 different roles, but I don't want duplicate user names. The
"Contains" ALWAYS is returning FALSE, so I'm not finding the dupe.
Here's the code:
Dim datalist As New List(Of TroubleTicketUser)
Dim str As String
Dim theroles(2) As String, therole As String
theroles(0) = "IT User"
theroles(1) = "IT Admin"
theroles(2) = "Customer Service Rep"
For Each therole In theroles
For Each str In Roles.GetUsersInRole(therole)
Dim tt As New TroubleTicketUser(str)
If Not datalist.Contains(tt) Then datalist.Add(tt)
Next
Next
datalist.Sort()
Return datalist
---------------------
Why doesn't the Contains work?

The Contains method works just fine, it just doesn't work the way that
you expected it to work.

The Contains method, when used on a List of reference types, checks if a
reference to the object exists in the list. As you create a new instance
of the TroubleTicketUser class, it's not the same object as the one that
exists in the list, eventhough they contain the same data.

What you want to do is to use a Dictionary(Of String, TroubleTicketUser)
where you use the user name as key.
Ok, I get it. However, from what I see, I can't sort a Dictionary.

Jul 31 '07 #4
Larry Bud wrote:
On Jul 31, 5:56 am, Göran Andersson <gu...@guffa.comwrote:
>Larry Bud wrote:
>>I have a function which return a List, and I'm trying to add users to
it from 3 different roles, but I don't want duplicate user names. The
"Contains" ALWAYS is returning FALSE, so I'm not finding the dupe.
Here's the code:
Dim datalist As New List(Of TroubleTicketUser)
Dim str As String
Dim theroles(2) As String, therole As String
theroles(0) = "IT User"
theroles(1) = "IT Admin"
theroles(2) = "Customer Service Rep"
For Each therole In theroles
For Each str In Roles.GetUsersInRole(therole)
Dim tt As New TroubleTicketUser(str)
If Not datalist.Contains(tt) Then datalist.Add(tt)
Next
Next
datalist.Sort()
Return datalist
---------------------
Why doesn't the Contains work?
The Contains method works just fine, it just doesn't work the way that
you expected it to work.

The Contains method, when used on a List of reference types, checks if a
reference to the object exists in the list. As you create a new instance
of the TroubleTicketUser class, it's not the same object as the one that
exists in the list, eventhough they contain the same data.

What you want to do is to use a Dictionary(Of String, TroubleTicketUser)
where you use the user name as key.

Ok, I get it. However, from what I see, I can't sort a Dictionary.
That is correct. You have to use an Array, a List or a SortedList for
that (or perhaps there are some more collections that can be sorted).

If you use a SortedList for example, you just have to loop through the
Values of the dictionary and add them to the list.

--
Göran Andersson
_____
http://www.guffa.com
Jul 31 '07 #5

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

Similar topics

3
by: Noam Dekers | last post by:
Hi all, I would like to find a word stored in a text file. Structure: I have one file named keyWords.txt that stores some key words I'm interested in finding. In addition I also have a file...
2
by: Steve | last post by:
Hi, I have a very long string, someting like: DISPLAY=localhost:0.0,FORT_BUFFERED=true, F_ERROPT1=271\,271\,2\,1\,2\,2\,2\,2,G03BASIS=/opt/g03b05/g03/basis,...
0
by: Dan Muey | last post by:
Howdy List! A couple questions about finding the disk space used by a = table/database: 1) First how can I get the size a table is taking up on disk? Is it the 'Data_length' field in: SHOW...
0
by: Paul | last post by:
This is the currernt table strucure PHP:-------------------------------------------------------------------------------- CREATE TABLE games_developers ( developers_id int(5) NOT NULL...
2
by: Antitax | last post by:
I have a database with more than 800 adress records Some of the are similar because some letters in the street adress for example are not identical, altough they point to the same adress. Does...
2
by: ElkGroveR | last post by:
Hi there! I'm using PHP to create a simple, dynamic MySQL SELECT query. The user chooses a selection from a HTML Form SELECT element's many options and submits the form via a POST action. ...
2
by: Extremest | last post by:
Here is the code I have so far. It connects to a db and grabs headers. It then sorts them into groups and then puts all the complete ones into another table. Problem I am having is that for some...
1
by: avik1612 | last post by:
Hi, I have created a program to find text files in a particular directory or folder. and to find a particular word in that files i finding it difficult to put the list in an array and finding...
0
NeoPa
by: NeoPa | last post by:
Introduction: This seems like a very straightforward topic. Why would anyone need help finding MS Access Help related to this topic? I can't really answer that except to say that I know from...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shćllîpôpď 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.