variable interpreting in VB.NET

F

Fred Nelson

I'm new to VB.NET and I have a situation in which I would like to interpret
a varialble - this may have another name in vb so I will explain what I
mean.

In FoxPro you can "interpret" a variable and get its value

For example:

dim vara as string = "1234"
dim varb as string = '5678"

dim myvar as string
dim myresult as string

myvar = "vara"
myresult = &myvar

In the last line myvar is "interpreted" using the "&" to be "vara" and the
variable "myresult" obtains the value that is in "vara" just as if I had the
following statement:

myresult = vara

Does anyone know if there is a way to do this in VB.NET - or for that matter
what this is called?

Your help would be greatly appreciated!

Thanks,

Fred
 
R

Rob Teixeira [MVP]

Basically, the value of myvar is a string representing the name of another
value.
Fox storage is a little different from other languages in some respects, and
I'm not sure there is *a* name for this sort of thing in VB, but it's
basically a use of RTTI (run-time type information) and
Reflection/Inspection.
In VB, you can use the CallByName function to do something similar. However,
CallByName is just a short-cut to the much richer functionality found in the
System.Reflection namespace, which allows you to inspect and call any method
defined in a class/structure, as well as access any class members by name.
In comparison, CallByName is rather limited.

-Rob Teixeira [MVP]
 
F

Fred Nelson

Rob:

Thanks for the post - I have checked out CallByName and it appears to do
everything that I need for this application so far.

I will also take a look at the system.reflections as you mention.

Thanks for your help!

Fred
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top