473,804 Members | 3,424 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 1545
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
13805
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
3000
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
3780
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
2361
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
7132
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
2855
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
2003
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
1363
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
5553
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
10569
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10325
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...
0
10075
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6847
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
5519
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
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.