Solved

Always want the first entry of a hash table

Posted on 2006-06-26
4
181 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

617 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