Get the most repeated item in ListBox- VB.NET

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

For this tutorial you need:

1 ListBox

1 Button

1 Label

Add some items to listbox:
Get the most repeated item in ListBox- vb.net
Add the Following link to Button1.Click event
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
        Handles Button1.Click
        Try
            Dim a, b, c As Object
            Dim d, f As Integer
            For Each a In ListBox1.Items
                For Each b In ListBox1.Items
                    If a = b Then
                        d += 1
                    End If
                Next
                If d > f Then
                    f = d
                    c = a
                End If
                d = 0
            Next
            Label1.Text = (c.ToString & " is repeated " & f & " times")
        Catch ex As Exception
        End Try
End Sub


Share This

Home | About | Contact | Privacy Policy

Copyright visual-basic-tutorials.com 2017 - All Rights Reserved.