• We just launched and are currently in beta. Join us as we build and grow the community.

Get the Most Repeated Text in a ListBox using VB.NET

vinnyboy16

Hilarity Manager
V Rep
0
0
0
Rep
0
V Vouches
0
0
0
Vouches
0
Posts
127
Likes
116
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
In this article, we will create a program that can determine the most repeated string or text inputted that is displayed in the ListBox.

Now, let's start this tutorial!

1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application.

2. Next, add one TextBox named TextBox1 that will serve as your input, two buttons named Button1 for adding the inputted text in the ListBox and Button2 for getting and displaying the most repeated text in a ListBox, and one listbox named ListBox1 for displaying the list of inputted text/items in the textbox. You must design your layout like this:

repeatdesign.png


3.Now put this code for your code module.
  1. Public

    Class

    Form1

  2. Private

    Sub

    Button1_Click(

    ByVal

    sender As

    System.

    Object

    , ByVal

    e As

    System.

    EventArgs

    )

    Handles

    Button1.

    Click
  3. ListBox1.

    Items

    .

    Add

    (

    TextBox1.

    Text

    )
  4. TextBox1.

    Clear

    (

    )
  5. End

    Sub

  6. Private

    Sub

    Button2_Click(

    ByVal

    sender As

    System.

    Object

    , ByVal

    e As

    System.

    EventArgs

    )

    Handles

    Button2.

    Click
  7. Dim

    ob1, ob2, ob3 As

    String
  8. Dim

    num1, num2 As

    Integer

  9. For

    Each

    ob1 In

    ListBox1.

    Items
  10. For

    Each

    ob2 In

    ListBox1.

    Items
  11. If

    ob1 =

    ob2 Then
  12. num1 +=

    1
  13. End

    If
  14. Next
  15. If

    num1 >

    num2 Then
  16. num2 =

    num1
  17. ob3 =

    ob1
  18. End

    If
  19. num1 =

    0
  20. Next
  21. MsgBox

    (

    ob3 &

    " is repeated "

    &

    num2 &

    " times"

    )
  22. End

    Sub
  23. End

    Class

Explanation:

For Button1, we used this button to add the inputted string in the textbox to be displayed in the listbox. Then after displaying, it will clear the inputted string inside the textbox.

For Button2, this button is used to determine the most repeated text inside the listview. We have initialized variable ob1, ob2, ob3 As String and variable num1, num2 As Integer. Then, we have created a nested For Each loop. We have first initialized variable ob1 in the for each loop to hold the items of the listbox, then the variable ob2. If variable ob1 and ob2 are equal num1 will increment by 1. if variable num1 is greater than variable num2 then the two variables will be equal and variable ob3 will now hold the value of variable ob3 then the num1 will be equal to be 0. The ob3 variable here holds the string value that is the most repeated text in the listbox and variable num2 holds the number of times it occurs in the listbox.

Output:

repeatoutput.png


Download the source code below and try it! :)

For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.

Best Regards,

Engr. Lyndon R. Bermoy

IT Instructor/System Developer/Android Developer

Mobile: 09079373999

Telephone: 826-9296

E-mail:[email protected]

Visit and like my page on Facebook at: Bermz ISware Solutions

Subscribe at my YouTube Channel at: SerBermz


Download
You must upgrade your account or reply in the thread to view hidden text.
 

452,292

323,517

323,526

Top