Click here to Skip to main content
11,925,381 members (64,424 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB VB.NET

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 8:20am
Edited 6-Dec-12 9:55am
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Try this:

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;

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
Adam R Harris 6-Dec-12 16:25pm
Nice solution.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Adam R Harris 6-Dec-12 13:24pm
Great answer! I love that site.
joshrduncan2012 6-Dec-12 13:26pm
Can you rate my answer, please?
Adam R Harris 6-Dec-12 13:33pm
Way ahead of you man, that's where the 5 stars came from.
joshrduncan2012 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web04 | 2.8.151126.1 | Last Updated 6 Dec 2012
Copyright © CodeProject, 1999-2015
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