Solved

Always want the first entry of a hash table

Posted on 2006-06-26
4
180 Views
Last Modified: 2010-04-23
Hi there

I am using a has table to store a field name in the key and a data type in the value

The first entry will be the Id I will be using for the table but the problem is when I want to pull this out I find it tricky
the below code brings out the first entry sorted on the key, rather than the first entry that was inserted

In a hastable is there a way to bring out the first entry inserted or should i do it another way


     Dim myEnumerator As IDictionaryEnumerator = PropList.GetEnumerator()
            TableID = ""
            If TableID = "" Then
                TableID = myEnumerator.Key
            End If
            While myEnumerator.MoveNext()
                TableID = ""
                If TableID = "" Then
                    TableID = myEnumerator.Key
                End If
                Select Case myEnumerator.Value.ToString.ToUpper


                    Case "STRING"
                        objStartPt.Insert(vbCr + ControlChars.Tab + ControlChars.Tab + ".Add(""@" + myEnumerator.Key + """, SqlDbType.VarChar, (200)).Value = dbprep.PrepareSPROCStr(" + Classname + "." + myEnumerator.Key + ")")
                    Case "INTEGER"
                        objStartPt.Insert(vbCr + ControlChars.Tab + ControlChars.Tab + ".Add(""@" + myEnumerator.Key + """, SqlDbType.int).Value = " + Classname + "." + myEnumerator.Key)
                    Case "BOOLEAN"
                        objStartPt.Insert(vbCr + ControlChars.Tab + ControlChars.Tab + ".Add(""@" + myEnumerator.Key + """, SqlDbType.bit).Value = " + Classname + "." + myEnumerator.Key)
                    Case "DATE"
                End Select
               
            End While
Regards

steve
0
Comment
Question by:davoman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 7

Expert Comment

by:pradeepsudharsan
ID: 16982617
Use IDictionary Interface  
0
 
LVL 1

Author Comment

by:davoman
ID: 16982619
that sounds good

how do i do that
0
 
LVL 34

Accepted Solution

by:
Sancler earned 500 total points
ID: 16982773
The basic answer to your question is that you cannot identify the "first" item in a hashtable.  It has no "order" other than that assigned by the hashtable itself based on the keys.  See this PAQ for instance

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21828523.html

What I would do in your situation is create a "first" record with a consistent key that is not going to be used for anything else - say "MyFirstKey".  I would then load the hashtable as normal except that, when I loaded the record that I wanted to be "first", I would add another record with "MyFirstKey" as its Key and the key from my "first" record as its Value.  Then, accessing the hashtable, to find the "first" record, I would use

     TableId = myHashTable(myHashTable("MyFirstKey"))

and stick a test in the subsequent enumeration to ignore both "MyFirstKey" and myHashTable("MyFirstKey") if/when they came up again.

Roger
0
 
LVL 1

Author Comment

by:davoman
ID: 16982865
Thats good enough for me


cheers for your help
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question