I'm having a lot of trouble with the Else statement in my For loop, and would like some help finding out what I'm doing wrong.
The loop is to decide whether or not the string in the input box is in my array or not.
Without the Else statement it works for the most part, however when I add the Else statement that's all it will output, even if the input is in the array.
What I want it to do is display "Match not found" in the output box when the input cannot be located in the array depending on which radio button is selected.
Here's my code:
Tip:
(aryProvTerr - Array containing the provinces and territories)
(aryAbrv - Array containing the abbreviations of the provinces and territories)
(rdoNtA - Radio button that determines which array you're going to search from (Name to Abbreviation))
Public Class frmMain
The loop is to decide whether or not the string in the input box is in my array or not.
Without the Else statement it works for the most part, however when I add the Else statement that's all it will output, even if the input is in the array.
What I want it to do is display "Match not found" in the output box when the input cannot be located in the array depending on which radio button is selected.
Here's my code:
Tip:
(aryProvTerr - Array containing the provinces and territories)
(aryAbrv - Array containing the abbreviations of the provinces and territories)
(rdoNtA - Radio button that determines which array you're going to search from (Name to Abbreviation))
Public Class frmMain
Dim aryProvTerr() As String = {"ALBERTA", "BRITISH COLUMBIA", "MANITOBA", "NEW BRUNSWICK", "NEWFOUNDLAND AND LABRADOR", "NORTHWEST TERRITORIES", _ Dim aryAbrv() As String = {"AB", "BC", "MB", "NB", "NL", "NT", "NS", "NU", "ON", "PE", "PQ", "SK", "YT"}
Private Sub btnSearch_Click(sender As Object, e As System.EventArgs) Handles btnSearch.Click
End Class"NOVA SCOTIA", "NUNAVUT", "ONTARIO", "PRINCE EDWARD ISLAND", "QUEBEC", "SASKATCHEWAN", "YUKON"}
Private Sub btnSearch_Click(sender As Object, e As System.EventArgs) Handles btnSearch.Click
Dim input As String = txtInput.Text
Dim n As Integer
If input = String.Empty Then
End SubDim n As Integer
If input = String.Empty Then
txtOutput.Text = "Input is empty."
ElseIf rdoNtA.Checked = True ThenFor n = 0 To (aryProvTerr.Length - 1)
ElseIf input.ToUpper = aryProvTerr(n) Then
NexttxtOutput.Text = aryAbrv(n)
ElsetxtOutput.Text = "Match not found" ' This is not working the way I want
End IfFor n = 0 To (aryAbrv.Length - 1)
End IfIf input.ToUpper = aryAbrv(n) Then
NexttxtOutput.Text = aryProvTerr(n)
ElsetxtOutput.Text = "Match not found" ' This is not working the way I want
End If