Case Select - Not the best way ..

I am trying to look up data in a grid.  I am using a Select Case statement, see below.  My question is there an another way to do this.  I have another table/grid of data that has 30 rows and 30 columns and my Select Case statement will be very big.

 

 

 



Answer this question

Case Select - Not the best way ..

  • Golm

    *grin* It was the best article my google search found, in terms of explaining how a hashtable works.



  • Sajay - MSFT

    Thank you for the suggestion, not really familiar with that. Do you have a reference or example that I might be able to use


  • edin

    http://support.microsoft.com/default.aspx scid=kb;en-us;309357

    Basically, this collection is looked up with a key, rather than an index. So, you can use any data you like to associate each record with a key for lookup.



  • lskvish

    Bad Christian, a C# example in a VB Forums. Beat yourself for that mistake....

    Code Example of simple hashtable in VB. Button 1 populate a hashtable with a list of objects. Button 2 searches for items with the key.

    Public Class Form1
    Private HT As New Hashtable

    Structure TestStruct
    Dim x As String
    Dim y As Integer
    Sub New(ByVal y1 As Integer, ByVal x1 As String)
    x = x1
    y = y1
    End Sub
    End Structure

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    HT.Clear()
    HT.Add("1", New TestStruct(100, "test 1"))
    HT.Add("2", New TestStruct(201, "test 2"))
    HT.Add("3", New TestStruct(320, "test 3"))
    HT.Add("4", New TestStruct(111, "test 4"))
    HT.Add("5", New TestStruct(100, "test 5"))
    HT.Add("6", New TestStruct(132, "test 6"))

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    If HT.ContainsKey(textbox1.text) Then
    Dim s As TestStruct = HT.Item(TextBox1.Text)
    Label1.Text = s.x
    Label2.Text = s.y
    Else
    Label1.Text = "Not Found"
    Label2.Text = ""
    End If
    End Sub
    End Class


  • Mudasser

    IMO the most elegant way to do that sort of lookup is to build a dictionary/hash table/map that links some sort of unique key with all the data you need to look up.



  • Case Select - Not the best way ..