Click here to Skip to main content
15,909,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,

Is it possible to update items in a hashtable?

I want to be able to update some items if any values need to be changed, however I have tried different ways of updating the values but either the values where the old values or it produced a Late-bound assignment error, and the Microsoft help page for that error is not very helpful: http://msdn.microsoft.com/en-us/library/dwkwy23c(v=vs.90).aspx[^]


Here is an example of what I am trying to achieve:

VB
dim i as integer = 0

hashtable.item(i).description = Description.Text


i is an integer which corresponds to the key in the hash-table.

Hope this makes sense, can anybody help me please?
Posted
Comments
Sergey Alexandrovich Kryukov 13-Aug-13 11:35am    
Please, exact type you are using?
—SA
Maciej Los 13-Aug-13 11:42am    
Not clear... ;(
Please be more specific and provide more details.
Willtwinny 13-Aug-13 12:00pm    
MsgBox(hashtable(i).description) <-- A structure which is stored in the HashTable along with an integer as the key, has a variable called description. This message box displays the description item to the user. (This works)
description.text <-- Displays the text that needs to replace the above description in the HashTable.

Both of these are descriptions are strings, however the key for the hash-table is a integer thus that is why 'i' is used.

Sorry I am not very good at explaining things.

Public Structure myStruct
Public Description As String
End Structure

Dim newStruct As myStruct
newStruct.description = "hello"
hshStodRates.add(0, newStruct)

Hope this helps.

The hashtable has no idea what you will put into it at time of compilation. You could use a dictionary and specify the type you are going to put into it. Otherwise you need to cast whatever your hashtable holds at some index to the right type.

Dim hashtableas Dictionary(Of Integer, SomeClass);


Good luck!
 
Share this answer
 
I decided in the end to just delete the old record from the hash-table and re-enter the values for the new/updated record.

Not really the solution to the problem (updating values in a hashtable) but it has the same outcome.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900