If someone can tell me what I'm doing wrong I would greatly appreciate it. I have a listbox of all the US states and an array of the capital of all the states. What I'm trying to do is when the state is selected and the button is clicked, then it will output the capital of state in a textbox. This is my code:
Public Class Form1
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim str1 As String
Dim CapitalsArray() As String = {"Montgomery", "Juneau", "Phoenix", "Little Rock",
"Sacramento", "Denver", "Hartford", "Dover", "Tallahassee", "Atlanta",
"Honolulu", "Boise", "Springfield", "Indianapolis", "Des Moines", "Topeka",
"Frankfort", "Baton Rouge", "Augusta", "Annapolis", "Boston", "Lansing",
"St. Paul", "Jackson", "Jefferson City", "Helena", "Lincoln", "Carson City",
"Concord", "Trenton", "Santa Fe", "Albany", "Raleigh",
"Bismarck", "Columbus", "Oklahoma City", "Salem", "Harrisburg", "Providence",
"Columbia", "Pierre", "Nashville", "Austin", "Salt Lake City", "Montpelier",
"Richmond", "Olympia", "Charleston", "Madison", "Cheyenne"}
str1 = " is the capital of the state "
Dim stateArray(50) As String
Dim i As Integer
For i = 0 To lstStates.Items.Count - 1
stateArray(i) = lstStates.Items(i)
Next
If lstStates.SelectedItem = i Then
stateArray(i) = CapitalsArray(i)
End If
txtOutput.Text = CapitalsArray(i) & str1 & stateArray(i)
End Sub