Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Always want the first entry of a hash table

Posted on 2006-06-26
4
Medium Priority
?
186 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 2000 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

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.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

772 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