Access class variables

Greetings, I have the following class

Public Class Controls
    Public FriendlyName As String
    Public Searchable As Boolean
End Class

And I have a function in a different class that  takes a controls name as a parameter, but I’m having trouble gaining access to the variables in the controls class.

Public Function GetFields(ByVal name As String) As string
        Dim HT As New Hashtable
        Dim Ctrl As Controls
       Dim Member as MemberInfo

        Ctrl = New Controls
        Member = ControlsCls.GetMember(name)      'This line is not working when name="searchable" for example!!!
        HT.Add("key1", Ctrl)
    End Function

Any idea how to access the content of the Controls Class (FriendlyName, Serachable, etc..)  Thanks.
ChaffeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

AlexFMCommented:
Ctrl = New Controls
Dim s as String = Ctrl.FriendlyName
Dim b as Boolean = Ctrl.Searchable
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
This code makes no sense though...

    Public Function GetFields(ByVal name As String) As string
        Dim HT As New Hashtable
        Dim Ctrl As Controls
        Dim Member as MemberInfo

        Ctrl = New Controls
        Member = ControlsCls.GetMember(name)     'This line is not working when name="searchable" for example!!!
        HT.Add("key1", Ctrl)
    End Function

You have declared the HashTable and the Controls objects INSIDE the function.  They will be created and the Controls instance will be added to the HashTable...but as soon as the GetFields() function has exited the variables will go out of scoped and be garbage collected!\

???



Perhaps you meant something more like?...

    Private HT As New HashTable

    Public Class Controls
        Public FriendlyName As String
        Public Searchable As Boolean
    End Class

    Public Sub AddNewControl(ByVal name As String, byVal searchabe As Boolean)
        Dim Ctrl As New Controls
        Ctrl.Friendlyname = name
        Ctrl.Searchable = searchable
        HT.Add(name, Ctrl)
    End Function

Now your instance is being stored in a HashTable that won't go out of scope...

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:
Thanks  Idle_Mind.  I got it working.
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.