I need to display the Aisle number in a label. My big issue here is with Arrays. Outside of math class, I am, pretty terrible at them.
The idea is to select a genre from a listbox and press a button and the program performs a lookup of the array to display the aisle number according to the genre.
I need to use the listbox SelectedIndex property to find the aisle number.
This is what I have so far.
I want to understand how to do this and WHY it works rather than just an answer, although one would be appreciated..
I have struggled with Arrays in programming for years and if I don't figure it out I may get burned out.
I have the form/gui all done I am having problems with the code.
Code:Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim tabledata(5, 2) As String tabledata(0, 0) = ("Aisle 1") tabledata(1, 0) = ("Aisle 2") tabledata(2, 0) = ("Aisle 3") tabledata(3, 0) = ("Aisle 4") tabledata(4, 0) = ("Aisle 5") tabledata(5, 0) = ("Back Wall") '''''''''''''''''''''''''''''''''''''' tabledata(0, 1) = ("Comedy") tabledata(1, 1) = ("Drama") tabledata(2, 1) = ("Action") tabledata(3, 1) = ("Sci-Fi") tabledata(4, 1) = ("Horror") tabledata(5, 1) = ("New Releases") ''''''''''''''''''''''''''''''''''''''' tabledata(0, 2) = (0) tabledata(1, 2) = (1) tabledata(2, 2) = (2) tabledata(3, 2) = (3) tabledata(4, 2) = (4) tabledata(5, 2) = (5) Dim genre As String genre = ListBox1.SelectedItem If genre = tabledata(0, 1) Then Label1.Text = tabledata(0, 0) End If End Sub End Class
If you just want some help with arrays you can check out these two tutorials:
http://forum.codecall.net/vb-tutoria...10-arrays.html
http://forum.codecall.net/vb-tutoria...al-arrays.html
I checked those first before I posted. I will go through them again and see if I get it this time.
I read through it again and I understand the basics it is trying to teach. I am still having a problem understanding how to implement my code though
You could probably do something like this:
Code:Dim genre As String genre = ListBox1.SelectedItem For i As Integer = 0 To tabledata.GetUpperBound(0) If genre = tabledata(i, 1) Then Label1.Text = tabledata(i, 0) Exit For End If Next
http://forum.codecall.net/vb-tutoria...-part-1-a.html
Happy to help![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks