473,671 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 TroubleTicketUs er)
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.GetUsersI nRole(therole)
Dim tt As New TroubleTicketUs er(str)
If Not datalist.Contai ns(tt) Then datalist.Add(tt )
Next
Next

datalist.Sort()

Return datalist

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

Jul 30 '07 #1
4 1539
On 30 juil, 15:26, Larry Bud <larrybud2...@y ahoo.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 TroubleTicketUs er)
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.GetUsersI nRole(therole)
Dim tt As New TroubleTicketUs er(str)
If Not datalist.Contai ns(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 TroubleTicketUs er)
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.GetUsersI nRole(therole)
Dim tt As New TroubleTicketUs er(str)
If Not datalist.Contai ns(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 TroubleTicketUs er 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, TroubleTicketUs er)
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.co mwrote:
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 TroubleTicketUs er)
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.GetUsersI nRole(therole)
Dim tt As New TroubleTicketUs er(str)
If Not datalist.Contai ns(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 TroubleTicketUs er 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, TroubleTicketUs er)
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.co mwrote:
>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 TroubleTicketUs er)
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.GetUsersI nRole(therole)
Dim tt As New TroubleTicketUs er(str)
If Not datalist.Contai ns(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 TroubleTicketUs er 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, TroubleTicketUs er)
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
13786
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 named textOrigin.txt in which I store the text to search in. I would like my prog to check if a certain word appears in the text and than to tell me what line it found it in (if it did...). My problem is that the script can't find the words I'm...
2
2994
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, GAMESS=/opt/gamess,GAUSS_ARCHDIR=/opt/g03b05/g03/arch, GAUSS_EXEDIR=/opt/g03b05/g03/bsd:/opt/g03b05/g03/private:/opt/g03b05/g
0
3774
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 TABLE STATUS FROM db_name LIKE = 'wild';?? If so how can I do a query like the one above and just get Data_length = returned? Otherwise what query can I do to find the disk size of a table?
0
2349
by: Paul | last post by:
This is the currernt table strucure PHP:-------------------------------------------------------------------------------- CREATE TABLE games_developers ( developers_id int(5) NOT NULL auto_increment, developers_name varchar(255) NOT NULL default ' ', language_id int(5) NOT NULL default '0', PRIMARY KEY (developers_id,language_id)
2
7126
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 anyone have the syntax for a query that shows similar adresses thar could be duplicates? Thank you
2
2843
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. The SELECT query is built as follows: $itemtype = stripslashes(trim($_POST));
2
1997
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 reason now it is not finding ones that are single posts. Here is an example of a header for a single. (Ask the Dust ) - "atd-ftc-repack.nfo" www.ctjes.com (1/1) (1/1) at the end means it is part 1 of a 1 part post. Any help would be...
1
1358
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 the words I have pasted the code below
0
5537
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 experience that many do. I myself spent a great deal of time under the impression that it was non-existent. How to Find it: Different versions of MS Access structure their help systems differently, so don't expect it to be in the same place for each...
0
8393
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8820
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8598
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7433
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6223
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5695
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4224
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2051
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.