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
Solved

Always want the first entry of a hash table

Posted on 2006-06-26
4
178 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
  • 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

861 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