Access hashtable values

Greetings, In the following code, I build a hashtable using setHT() and I'm attempting to use GetHT() to gain access the value of the fields in the hashtable items, but I haven't been able to do so (ie: I'm trying to access the value of F2.Search)
What do I need to get to that value?  Thanks.

Public Class Fields
    Public FM As String
    Public Search As String
End Class
‘-----------------------------------------------------
Public Class work
Private m_FieldsSpecs As Hashtable

    Public ReadOnly Property FieldsSpecs() As Hashtable
        Get
            If m_FieldsSpecs Is Nothing Then SetFieldsSpecs()
            Return m_FieldsSpecs
        End Get
    End Property

Public Sub setHT()
        Dim f As New Fields

        f.FM = "FM1"
        f.Search = "Sea1"
        FieldsSpecs.Add("F2", f)

        f = New Fields
        f.FM = "FM2"
        f.Search = "Sea2"
        FieldsSpecs.Add("F2", f)
    End Sub

Public Sub GetHT()
        For Each var As DictionaryEntry In FieldsSpecs
            Type.GetType(var.Value.ToString).GetField("Searchable").GetValue(var.Value.ToString)  'This is not working.....
        Next
    End Function
End Class
ChaffeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ChaffeAuthor Commented:
Note: a typo in the GetHT function.
'-----------------------------------------
Public Sub GetHT()
        For Each var As DictionaryEntry In FieldsSpecs
            Type.GetType(var.Value.ToString).GetField("Search").GetValue(var.Value.ToString)  'This is not working.....
        Next
End Function
0
cubixSoftwareCommented:
Hi

To access the values via a DictionaryEntry

Public Sub GetHT()

        dim var as IDictionaryEnumerator = FieldsSpecs.GetEnumerator()
        While var.MoveNext
            messagebox.Show("My key is " & var.Key & " and my value is " & var.Value)
        Next

End Function
0
cubixSoftwareCommented:
....

Hashtables work on Key/Value pairs so when you set values you must give it a Key and then a Value. In your setHT method you are using the same key "F2" so I am surprised your not getting some error here.

There seems to be a key you are using, ie FM1 and FM2 so you could use these as keys as follows

Public Sub setHT()
        Dim f As New Fields

        f.FM = "FM1"
        f.Search = "Sea1"
        FieldsSpecs.Add("FM1", f)

        f = New Fields
        f.FM = "FM2"
        f.Search = "Sea2"
        FieldsSpecs.Add("FM2", f)
    End Sub

or simply have an incrementing number

Public Sub setHT()
        Dim f As New Fields

        f.FM = "FM1"
        f.Search = "Sea1"
        FieldsSpecs.Add("1", f)

        f = New Fields
        f.FM = "FM2"
        f.Search = "Sea2"
        FieldsSpecs.Add("2", f)
    End Sub





HTH :)
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

ChaffeAuthor Commented:
cubixSoftware,  I acutally have 2 different keys in my code, this is just another typo in my example above.  I apologize.
in the function GetHT(), var.Value is giving me an object instance of the Fields class (with 2 fields in it and their values)
just to give you an example, when I loop in GetHT I get this in my first loop...

For Each var As DictionaryEntry In FieldsSpecs
    var.key     'This gives  "F1"
    var.value   'is getting me {Fields} and it has 2 fields in this object (FM & Serach and their values "FM1" & "Sea1")
Next

my goal here is to get a hold of the values of the object fields (FM & Search.)  Any thoughts on how to do this?  Thanks.
0
cubixSoftwareCommented:
Can you try the following

dim field1 as string
dim field2 as string

field1 = ctype(var.value,Fields).FM
field2 = ctype(var.value,Fields).Search

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ChaffeAuthor Commented:
cubixSoftware, That did it.  Thanks for your help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.