A TA at my college recommended Dream In Code as a resource that is available for help with coding problems.
I have been trying to figure out how to get my code to work. (It was a homework assignment which has already been turned in but I am determined to get this code to work.)
I have a text box titled txtSearch and btnClick.
I need to search a list box for a city name and then have it displayed in a message box. If there is not a match then I need to display an alternative message box stating there is no match. City is in the list box starting at 16.
The text needs to be case insensitive.
Any help would be appreciated.
I am only getting the message "That is not a valid city." for any entry that I type into my txtSearch even though I know it should be a match.
Here is what I have for code
Private Sub btnFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFind.Click ' Declare variables to find text on txtSearch when button clicked Dim length As Integer = txtSearch.TextLength Dim value As String = txtSearch.Text.ToUpper Dim Selected As String Dim ssstring As String 'Loops through Weather list box to find matching city For i As Integer = 0 To lstWeather.Items.Count - 1 lstWeather.SelectedIndex = i Selected = lstWeather.SelectedItem.ToString.ToUpper ssstring = Selected.Substring(16, length) If value = ssstring Then ' If ssstring = value Then ShowMessage("City Record Found") Else MessageBox.Show(" That is not a valid city.", "Information", MessageBoxButtons.OK, _ MessageBoxIcon.Information, MessageBoxDefaultButton.Button1) 'Replaces the search criteria with original text txtSearch.Text = ("Search city by 1st letter.") 'Change the color of the search box to Blue txtSearch.ForeColor = Color.Blue Exit Sub End If Next End Sub