I am learning about the search capability in an array. I wrote a code that stores three names (first & last) and I want to:
- Make the user select a number (from 1-3) by using a (combobox)
- If the user select the proper number then a message will appear that the name is there.
- If not then an error message will appear.
I did all I could by creating this but my main problem is in the (ButtonFind). I went through lots of tutorials and this is what I came up with and I hope that my code is correct.
I appreciate the help and thank you in advance.
Public Class Form1 Structure NamesInfo Dim FirstName As String Dim LastName As String Dim NamesNumber As Integer End Structure Public NamesArray(4) As NamesInfo Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load NamesArray(1).FirstName = "James" NamesArray(1).LastName = "Bond" NamesArray(1).NamesNumber = 1 NamesArray(2).FirstName = "Jack" NamesArray(2).LastName = "Black" NamesArray(2).NamesNumber = 2 NamesArray(3).FirstName = "Michael" NamesArray(3).LastName = "Jordan" NamesArray(3).NamesNumber = 3 NamesArray(4).FirstName = "Mickey" NamesArray(4).LastName = "Mouse" NamesArray(4).NamesNumber = 4 End Sub Private Sub ButtonFind_Click(sender As System.Object, e As System.EventArgs) Handles ButtonFind.Click 'Get the number from the combobox 'Create 2 variables of Name (Name & FoundName) 'Use for loop ' For Each Name In NameArray ' If (the Name Number is the one we are looking for) Then ' Messagebox and write "We found the name" ' End If 'Next ' Messagebox "The name wansn't found" ' End Sub ' End Class