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-
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
            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
                If d > f Then
                    f = d
                    c = a
                End If
                d = 0
            Label1.Text = (c.ToString & " is repeated " & f & " times")
        Catch ex As Exception
        End Try
End Sub

Share This

Home | About | Contact | Privacy Policy

Copyright 2017 - All Rights Reserved.