Closed Thread
Results 1 to 7 of 7

Thread: Working with Arrays and listbox to perform lookup

  1. #1
    anglina's Avatar
    anglina is offline Learning Programmer
    Join Date
    Jan 2009
    Location
    Vientiane, Laos
    Posts
    76
    Rep Power
    0

    Working with Arrays and listbox to perform lookup

    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

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Join Date
    Apr 2009
    Location
    Uppsala, Sweden
    Posts
    9,547
    Blog Entries
    5
    Rep Power
    98

    Re: Working with Arrays and listbox to perform lookup

    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

  4. #3
    anglina's Avatar
    anglina is offline Learning Programmer
    Join Date
    Jan 2009
    Location
    Vientiane, Laos
    Posts
    76
    Rep Power
    0

    Re: Working with Arrays and listbox to perform lookup

    I checked those first before I posted. I will go through them again and see if I get it this time.

  5. #4
    anglina's Avatar
    anglina is offline Learning Programmer
    Join Date
    Jan 2009
    Location
    Vientiane, Laos
    Posts
    76
    Rep Power
    0

    Re: Working with Arrays and listbox to perform lookup

    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

  6. #5
    Join Date
    Apr 2009
    Location
    Uppsala, Sweden
    Posts
    9,547
    Blog Entries
    5
    Rep Power
    98

    Re: Working with Arrays and listbox to perform lookup

    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

  7. #6
    anglina's Avatar
    anglina is offline Learning Programmer
    Join Date
    Jan 2009
    Location
    Vientiane, Laos
    Posts
    76
    Rep Power
    0

    Re: Working with Arrays and listbox to perform lookup

    Quote Originally Posted by Vswe View Post
    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

    Awesome! This is exactly what I was looking for.

    I understand the loops, I just need to read about the .GetUpperBounds part

    Thanks so much!

  8. #7
    Join Date
    Apr 2009
    Location
    Uppsala, Sweden
    Posts
    9,547
    Blog Entries
    5
    Rep Power
    98

    Re: Working with Arrays and listbox to perform lookup

    Happy to help

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to perform custom painting in Java?
    By Omar Luna in forum Java Help
    Replies: 2
    Last Post: 10-14-2011, 08:15 AM
  2. Beginner Working with TextBox, ComboBox, ListBox and Button controls
    By Tonchi in forum CSharp Tutorials
    Replies: 0
    Last Post: 03-28-2011, 07:55 AM
  3. Perform Basic Cleanup Through Terminal
    By Rabbitdog in forum Linux/Unix General
    Replies: 1
    Last Post: 06-25-2010, 07:41 PM
  4. Implementing Lookup table
    By bhishak in forum C and C++
    Replies: 1
    Last Post: 05-19-2010, 09:30 PM
  5. Want to Perform a Task at Specific Time...
    By tif in forum General Programming
    Replies: 1
    Last Post: 04-24-2009, 03:44 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts