Public Class videoBonanzaForm

    Dim videoBonanza(,) As String = {{"Comedy", "Aisle 1"}, {"Drama", "Aisle 2"}, {"Action", "Aisle 3"}, _
                                      {"Sci-Fi", "Aisle 4"}, {"Horror", "Aisle 5"}, {"New Releases", "Back Wall"}}

    Private Sub videoBonanzaForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub searchButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles searchButton.Click
        If categoriesListBox.SelectedIndex = -1 Then
            MessageBox.Show("No Category Selected!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
            aisleLabel.Text = videoBonanza(categoriesListBox.SelectedIndex, categoriesListBox.SelectedIndex)
        End If
    End Sub
End Class

I get an error at the Else statement during run time. Why can I not access the element this way?

Edited 4 Years Ago by Dani: Formatting fixed

You problem is your array is 2 wide. When you get to an index of 3 your code is trying to read a(1,2,3)
Do this instead:

aisleLabel.Text = videoBonanza(categoriesListBox.SelectedIndex, 0)
- or -
            aisleLabel.Text = videoBonanza(categoriesListBox.SelectedIndex, 1)
This article has been dead for over six months. Start a new discussion instead.