By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,573 Members | 1,812 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,573 IT Pros & Developers. It's quick & easy.

Name of Variable at Runtime

P: n/a
Hi

Is there any way of finding out the name of a variable at Runtime?

I am working on solution to add all member variables of a class to a
collection and write them to file in pairs of name=value, that will save the
need to modify the file read/write method each time I add a member variable
to the class as well as ther initial code

The only other way is to use class object or add an extra member to the
collection for each memeber in the correct order

Thank you,
Shmuel Shulman
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"S Shulman" <sm*******@hotmail.com> schrieb:
Is there any way of finding out the name of a variable at Runtime?

I am working on solution to add all member variables of a class to a
collection and write them to file in pairs of name=value, that will save
the need to modify the file read/write method each time I add a member
variable to the class as well as ther initial code


\\\
Imports System.Reflection
Imports System.Reflection.BindingFlags
Imports System.Reflection.MemberTypes
..
..
..
Dim typ As Type = GetType(Form1)
For Each fi As FieldInfo In typ.GetFields(Instance Or NonPublic)
Dim Value As Object = fi.GetValue(Me)
Dim s As String
Try
s = Value.ToString()
Catch ex As Exception
s = ""
End Try
MsgBox(fi.Name & " = " & s)
Next fi
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #2

P: n/a
"S Shulman" <sm*******@hotmail.com> schrieb
Hi

Is there any way of finding out the name of a variable at Runtime?

I am working on solution to add all member variables of a class to a
collection and write them to file in pairs of name=value, that will
save the need to modify the file read/write method each time I add a
member
variable to the class as well as ther initial code

The only other way is to use class object or add an extra member to
the collection for each memeber in the correct order


http://msdn.microsoft.com/library/en...asp?frame=true

http://msdn.microsoft.com/library/en...asp?frame=true

Armin

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.