Solved

Always want the first entry of a hash table

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now