• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 253
  • Last Modified:

String indexed collection

I'm looking for a tutorial in VB.NET (instead of VB6) on something similar to the project in this link "A Fast Index-Based Collection"
http://www.vbaccelerator.com/home/vb/Code/Techniques/A_Fast_Index-Based_Object_Collection/article.asp
I'm intersted in building a collection with a string index that I can use to store values in it's objects.  Thanks.
0
Chaffe
Asked:
Chaffe
2 Solutions
 
123654789987Commented:
0
 
doobdaveCommented:
Hi there,

I think you should be able to use a hashtable to achieve what you want.

Look it up in the MSDN.

Hope to help.

David
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You can't access a HashTable by Index though.  It is possible to access the Keys/Values collections by Index, but they are sorted based on the hash value of the Key...not the insertion order.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
ChaffeAuthor Commented:
just to give you a little idea on what I'm tyring to do, I get  a query string in my URL of my web application (?pageid=1) and I use that id do everything in my application.  I got to a point where I have a select case in every function that checks for the PageId.
my goal is to try and get away from all these select cases by creating some sort of collection that I can reference by pageid (similar to a primary key in a sql table) and be able to store some values (such as function names, lables, etc...) by this index.
I considered having a SQL table to store all this and query it on every request, but if I can accomplish the same thing without a trip to the DB, it'll be better.  Any thoughts?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Then I think doobdave was correct after all in his suggestion of a HashTable.

Create a Class to hold the info you want and store that in the HashTable using the pageid as the Key.

Here is a simple example...

    Public Class Dog
        Public Name As String
        Public Breed As String
        Public Naughty As Boolean
    End Class

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ht As New Hashtable

        Dim d As New Dog
        d.Name = "Fido"
        d.Breed = "Wire Haired Fox Terrier"
        d.Naughty = True
        ht.Add("dog1", d)

        d = New Dog
        d.Name = "Lassie"
        d.Breed = "Labrador"
        d.Naughty = False
        ht.Add("dog2", d)

        d = ht.Item("dog1")
        MsgBox(d.Name & ", " & d.Breed & ", " & d.Naughty)

        d = ht.Item("dog2")
        MsgBox(d.Name & ", " & d.Breed & ", " & d.Naughty)
    End Sub
0
 
ChaffeAuthor Commented:
Idle_Mind & doobdave,
Thanks.  I think this is what I'm looking for.  Since I already know what everthing is going to be based on my id, I will be "hardcoding" these properties (.breed, .name, etc...)
Do you think I should have these properties in a structure and have a function inside that structure (similar to the Button1_Click in your example) that would do all the assignments.  And just call this function on every request.  Or is there a better way.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
I don't do web based development unfortunately so I don't know the ins and outs of variable scope/lifetime across page requests etc...

Perhaps doobdave has some input on that aspect?..
0
 
ChaffeAuthor Commented:
Thanks Idle_Mind  for the help.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now