|
-
Oct 2nd, 2010, 03:06 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Count Duplicate entries in TextBoxes
Hello.
I have 50 Texboxes.
I need to count the number of duplicate entries, and provide a summary (count) for each product code. This makes it easier when the order needs to be placed, and the user don't have to count each value manually.
Any idea on how to do this. I have tried looping through all 50 boxes to no avail. This seemed easy, but, clearly I am to thick to think of a solution.
Any help will be appreciated.
-
Oct 2nd, 2010, 04:00 AM
#2
Fanatic Member
Re: Count Duplicate entries in TextBoxes
Uhhh this is the only solution that popped to my head when I looked at it. No doubt there are probably cleaner methods:
vb Code:
Dim totalrep as int32 = 0 For each tb As TextBox In Me.Controls Dim myText As String = tb.Text For each txtBox As TextBox In Me.Controls if txtBox.Text = myText then totalrep += 1 End If Next Next
Only glaring problem I see is duplicate counts (i.e TextBox2.Text = TextBox1.Text and TextBox1.Text = TextBox2.text) which would result in double results. So yeah, I guess you'd have to figure out how to fix that (I'm not sure if dividing the final result by 2 would do it...just a suggestion)
-
Oct 2nd, 2010, 04:02 AM
#3
Fanatic Member
Re: Count Duplicate entries in TextBoxes
Uhhh this is the only solution that popped to my head when I looked at it. No doubt there are probably cleaner methods:
vb Code:
Dim totalrep as int32 = 0
For each tb As TextBox In Me.Controls.ofType(of textbox)
Dim myText As String = tb.Text
For each txtBox As TextBox In Me.Controls.oftype(of textbox)
if txtBox.Text = myText then
totalrep += 1
End If
Next
Next
Only glaring problem I see is duplicate counts (i.e TextBox2.Text = TextBox1.Text and TextBox1.Text = TextBox2.text) which would result in double results. So yeah, I guess you'd have to figure out how to fix that (I'm not sure if dividing the final result by 2 would do it...just a suggestion)
-
Oct 2nd, 2010, 04:23 AM
#4
Re: Count Duplicate entries in TextBoxes
may be you can try this:
Code:
Private Function GetProductSummary() As DataTable
Dim dtSummary As DataTable
Dim dcCol As DataColumn
Dim txtBox As Control
Try
dtSummary = New DataTable("Order")
dcCol = New DataColumn("ProductCode", Type.GetType("System.String"))
dtSummary.Columns.Add(dcCol)
dcCol = New DataColumn("Qty", Type.GetType("System.Int32"))
dtSummary.Columns.Add(dcCol)
For Each txtBox In Me.Controls
If txtBox.GetType.Name = "TextBox" Then
Dim drProducts() As DataRow
drProducts = dtSummary.Select("ProductCode = '" & txtBox.Text.Trim & "'")
If drProducts.Length > 0 Then
drProducts(0).Item("ProductCode") = txtBox.Text.Trim
drProducts(0).Item("Qty") += 1
Else
Dim drProduct As DataRow = dtSummary.NewRow
drProduct.Item("ProductCode") = txtBox.Text.Trim
drProduct.Item("Qty") = 1
dtSummary.Rows.Add(drProduct)
End If
End If
Next
Return dtSummary
Catch ex As Exception
Throw ex
End Try
End Function
__________________
Rate the posts that helped you 
-
Oct 2nd, 2010, 04:49 AM
#5
Thread Starter
Hyperactive Member
Re: [RESOLVED] Count Duplicate entries in TextBoxes
Thank you guys!!!!
Doing it via a datatable never crossed my mind.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|