• Congratulations to the Class of 2024 on your results!
    Let us know how you went here
    Got a question about your uni preferences? Ask us here

Linear Search in VB.NET (1 Viewer)

nakappe

New Member
Joined
Jan 24, 2019
Messages
16
Gender
Undisclosed
HSC
2019
Hi, so I've been working on this program on VB.NET to find how many results exist in a list through linear search. I have managed to code to find if something exists in a list, but I'm not sure how you can display the amount of results found in the list, for example, how many John's are in the list of names. Could anybody help me with this? Thank you in advance.

My current coding is below:

Private Sub btmLinearSearch_Click(sender As Object, e As EventArgs) Handles btmLinearSearch.Click

Dim stNames(24) As String

stNames(0) = "Elf"
stNames(1) = "Rudolf"
stNames(2) = "Star"
stNames(3) = "Grinch"
stNames(4) = "Angel"
stNames(5) = "Santa"
stNames(6) = "Present"
stNames(7) = "Crackers"
stNames(8) = "Carol Singers"
stNames(9) = "Xmas Trees"
stNames(10) = "Baubles"
stNames(11) = "Cookies"
stNames(12) = "Mistletoe"
stNames(13) = "Carrots"
stNames(14) = "Milk"
stNames(15) = "Present"
stNames(16) = "Sack"
stNames(17) = "Pudding"
stNames(18) = "Snowman"
stNames(19) = "Bilby"
stNames(20) = "Uluru"
stNames(21) = "Sleigh"
stNames(22) = "North Pole"
stNames(23) = "Candy Cane"
stNames(24) = "Present"

Dim stFind As String
stFind = Me.txtFind.Text

Dim bFound As Boolean
For iCount As Integer = 0 To 24
If stNames(iCount) = stFind Then
bFound = True
Exit For
End If
Next

If bFound = True Then
MsgBox("found " & stFind)
Else
MsgBox(stFind & " not found")
End If
End Sub

I want now to make it so that it displays that there are 3 "Presents" in the list.
 
Last edited:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top