• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 202
  • Last Modified:

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.
0
Chaffe
Asked:
Chaffe
1 Solution
 
AlexFMCommented:
Ctrl = New Controls
Dim s as String = Ctrl.FriendlyName
Dim b as Boolean = Ctrl.Searchable
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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...
0
 
ChaffeAuthor Commented:
Thanks  Idle_Mind.  I got it working.
0
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.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Tackle projects and never again get stuck behind a technical roadblock.
Join Now