Hey,

The GetField method, just like any GetXXX method of a type, takes flags to
determine the scope and visibility of the member you look at.

That works:

Public Class Class1
    Private m_varName As String
    Private m_value As String

    Shared Sub Main()
        Dim c As Class1

        c = New Class1()
        c.ExtractValue()
        Console.ReadLine()
    End Sub

    Private Sub ExtractValue()
        Dim _fieldInfo As System.Reflection.FieldInfo
        Dim _value As String

        m_varName = "m_value"
        m_value = "some value"

        _fieldInfo = Me.GetType().GetField(m_varName,
Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic)

        _value = _fieldInfo.GetValue(Me).ToString()
        Console.WriteLine(_value)
    End Sub
End Class


The _value variable will contain the string "some value".

Cheers,
Dave.

www.omniscienttrader.com
www.omniscient.ca


-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Jon Rothlander
Sent: April 19, 2007 4:40 PM
To: [email protected]
Subject: Re: [ADVANCED-DOTNET] Creating filling a textbox from a string...
sort of

That is an option that I have looked at.  However, at that point why not
just hard code them.  Building all of the properties would take much longer
than just hard coding this.

What about GetField() versus GetProperty()?  It seems that GetField() has
access to the variables, but I cannot retrieve anything from them through
GetField().  Maybe that's not possible.

I just figured that the variables are stored somewhere.  Why can't I get to
them like I can get to the controls on the form through Me.Controls.

I think the easiest option may be to just move the local string variables
out to the form as hidden fields.  Then I can use the form's control
collection, as the hidden textboxes will be in the collection where the
variables are not contained in a collection that I can parse through.




-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Bob Provencher
Sent: Thursday, April 19, 2007 2:37 PM
To: [email protected]
Subject: Re: [ADVANCED-DOTNET] Creating filling a textbox from a string...
sort of

The second option probably wouldn't work the way you want because you'd have
to code the property names... Which is the same as coding the variable
names.

If you change the locals to be properties of an object, you can then use
reflection to get the values you want off of the object through
type.GetProperty, and then PropertyInfo.GetValue.

-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of brian zinn
Sent: Thursday, April 19, 2007 3:08 PM
To: [email protected]
Subject: Re: [ADVANCED-DOTNET] Creating filling a textbox from a string...
sort of

I think what you're asking is impossible - sounds like reflection on
variable names.

Just use a Dictionary<string, string>, make your array 2 dimensional
or pass in an object with properties like FirstName...

===================================
This list is hosted by DevelopMentorR  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentor.  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to