Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42728

VS 2010 [RESOLVED] Array Else Statement Not Working As Intended

$
0
0
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
Dim aryProvTerr() As String = {"ALBERTA", "BRITISH COLUMBIA", "MANITOBA", "NEW BRUNSWICK", "NEWFOUNDLAND AND LABRADOR", "NORTHWEST TERRITORIES", _
"NOVA SCOTIA", "NUNAVUT", "ONTARIO", "PRINCE EDWARD ISLAND", "QUEBEC", "SASKATCHEWAN", "YUKON"}
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
Dim input As String = txtInput.Text
Dim n As Integer

If input = String.Empty Then
txtOutput.Text = "Input is empty."

ElseIf rdoNtA.Checked = True Then
For n = 0 To (aryProvTerr.Length - 1)
If input.ToUpper = aryProvTerr(n) Then
txtOutput.Text = aryAbrv(n)
Else
txtOutput.Text = "Match not found" ' This is not working the way I want
End If
Next

Else
For n = 0 To (aryAbrv.Length - 1)
If input.ToUpper = aryAbrv(n) Then
txtOutput.Text = aryProvTerr(n)
Else
txtOutput.Text = "Match not found" ' This is not working the way I want
End If
Next

End If
End Sub
End Class

Viewing all articles
Browse latest Browse all 42728

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>