Stoffel85 Posted January 12, 2005 Posted January 12, 2005 Hi, I have a problem showing an value from a hashtable Here is how I fill it up Do While dr.Read() hsCat.Add(i, "Test") i += 1 Loop And here is how I try to read it Public Sub VulIn(ByVal pos As Integer) If (pos > -1) Then txtText.text = hsCat.Item(pos) End If End Sub But that won't work because a conversion fromSystem.Object To Integer is not allowed when Option Strict On Any help? Quote
Administrators PlausiblyDamp Posted January 12, 2005 Administrators Posted January 12, 2005 Are you sure it is complaining that it cannot convert from object to integer? I would have expected it to fail converting from Object to String when assigning to the textbox but that could be fixed by txtText.Text = hsCat.Item(5).ToString() If it really is failing on converting to an integer on which line is the error occurring? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Stoffel85 Posted January 12, 2005 Author Posted January 12, 2005 Thanks It was indeed complaining about the conversion of System.Object to String Quote
Stoffel85 Posted January 12, 2005 Author Posted January 12, 2005 Is it also possible to add an array as value in the hashtable? and if yes, how do I read it? Quote
Administrators PlausiblyDamp Posted January 12, 2005 Administrators Posted January 12, 2005 something like Dim a() As String = {"a", "b", "c"} Dim h As New Hashtable() h.Add("test", a) Dim b() As String b = DirectCast(h.Item("Test"), String()) should do the trick Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.