?
Solved

Access class variables

Posted on 2006-04-14
3
Medium Priority
?
200 Views
Last Modified: 2010-04-24
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
Comment
Question by:Chaffe
3 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 16459035
Ctrl = New Controls
Dim s as String = Ctrl.FriendlyName
Dim b as Boolean = Ctrl.Searchable
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 750 total points
ID: 16461068
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
 

Author Comment

by:Chaffe
ID: 16494945
Thanks  Idle_Mind.  I got it working.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question