Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
Hi,
 
how can i check if there's a duplicate value in array?
Dim array(9) as String
 
array(0) = Textbox1.Text
array(1) = Textbox2.Text
array(2) = Textbox3.Text
array(3) = Textbox4.Text
array(4) = Textbox5.Text
array(5) = Textbox6.Text
array(6) = Textbox7.Text
array(7) = Textbox8.Text
array(8) = Textbox9.Text
array(9) = Textbox10.Text
 
if there's a duplicate value or text then the backcolor of the textbox turns to red.
 

any help will be highly appreciated.
Posted 6-Dec-12 7:20am
Edited 6-Dec-12 8:55am
ridoy51.7K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Try this:
 
C#
IEnumerable<Control> ctls = this.Controls.Cast<Control>();
var txtBoxQuery = from c in ctls
                  where c is TextBox && ctls.Count(x => x.Text == c.Text) > 1
                  select c;
foreach (Control c in txtBoxQuery)
        c.BackColor = Color.Red;
 

VB
  
Dim ctls As IEnumerable(Of Control) = Me.Controls.Cast(Of Control)()
Dim txtBoxQuery = From c In ctls Where TypeOf c Is TextBox And ctls.Count(Function(x) x.Text = c.Text) > 1 Select c
For Each c As Control In txtBoxQuery
   c.BackColor = Color.Red
Next
  Permalink  
v7
Comments
Adam R Harris at 6-Dec-12 16:25pm
   
Nice solution.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
Adam R Harris at 6-Dec-12 13:24pm
   
Great answer! I love that site.
joshrduncan2012 at 6-Dec-12 13:26pm
   
Can you rate my answer, please?
Adam R Harris at 6-Dec-12 13:33pm
   
Way ahead of you man, that's where the 5 stars came from.
joshrduncan2012 at 6-Dec-12 13:35pm
   
Thanks Adam! Sometimes I can't tell when something has been voted on or not.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 363
1 Sergey Alexandrovich Kryukov 286
2 RyanDev 75
3 nv3 60
4 PhilLenoir 60
0 Sergey Alexandrovich Kryukov 6,691
1 OriginalGriff 6,119
2 CPallini 2,473
3 Richard MacCutchan 1,697
4 Abhinav S 1,560


Advertise | Privacy | Mobile
Web02 | 2.8.140821.2 | Last Updated 6 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100