Hashtable does not work correct

corwin42

Expert
Licensed User
Longtime User
I wanted to port a hashtable from agrahams collection library to the internal hashtable and found out that it doesn't work correct.
I think the problem is removing an item:

B4X:
Sub App_Start
 hashtable1.Add("apple", "green")
 hashtable1.Add("ball", "blue")
 hashtable1.Add("train", "black")
 Msgbox("Train: " & hashtable1.Item("train"))
 hashtable1.Remove("ball")
 ' This gives an out of index error!
 'Msgbox("Train: " & hashtable1.Item("train"))
 hashtable1.Add("ball", "yellow")
 Msgbox("Train: " & hashtable1.Item("train"))
End Sub

First MsgBox says "Train: black" which is correct.
Second MsgBox gives an out of index error.
Third MsgBox (after commenting out the second one) says "Train: yellow" which is wrong.

BTW: If I try to use the hashtable from agrahams collection library I cannot compile because it gives an error of duplicate object "hashtable".

Greetings,
Markus
 

corwin42

Expert
Licensed User
Longtime User
I don't know how the data is saved internally but would it be possible to implement an Update(key, value) method? Currently I have to do a Remove() and then Add() to update the value of a key.
 

agraham

Expert
Licensed User
Longtime User
IIf I try to use the hashtable from agrahams collection library I cannot compile because it gives an error of duplicate object "hashtable".
Once the new release is official I will probably reissue the Collection library with the collections renamed something like HashTableEx, StackEx etc. to avoid name conflicts.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…