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

Using content of variable

P: n/a
Years ago there used to be a feature in dBase and FoxPro
where the content of a variable could be used a variable
name:

Var1 = "Var2"
Var2 = blank
&Var1 = "Hallo"

this way Var2 would get the value "Hallo" assigned.
By prefixing Var1 with the empersand the program would use
the content of Var1 rather than Var1 itself.

Can this be done in VB.NET?

thanks
tino

Nov 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi Tino,

Strange patterns occur sometimes. The same question but from a different
viewpoint appears only minutes apart from yours. So the same answer for both!
;-)

Have a look and see if CallByName is of any use to you.

If that's not suitable, the next to look at is the Type class. (use
GetType on the object which owns the method/member that you are interested.
This has GetField/GetFields and GetMember/s which may do the job.

Regards,
Fergus
Nov 20 '05 #2

P: n/a
* "tino" <td*@odic.tc> scripsit:
Years ago there used to be a feature in dBase and FoxPro
where the content of a variable could be used a variable
name:

Var1 = "Var2"
Var2 = blank
&Var1 = "Hallo"

this way Var2 would get the value "Hallo" assigned.
By prefixing Var1 with the empersand the program would use
the content of Var1 rather than Var1 itself.

Can this be done in VB.NET?


There is no way to do that with local variables. For other public
fields, properties or methods have a look at the thread above this one.

--
Herfried K. Wagner
MVP VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #3

P: n/a
Hi Tino,

If you have any question on this issue please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #4

P: n/a
thanks for your help ... a shame though ...

-----Original Message-----
* "tino" <td*@odic.tc> scripsit:
Years ago there used to be a feature in dBase and FoxPro where the content of a variable could be used a variable name:

Var1 = "Var2"
Var2 = blank
&Var1 = "Hallo"

this way Var2 would get the value "Hallo" assigned.
By prefixing Var1 with the empersand the program would use the content of Var1 rather than Var1 itself.

Can this be done in VB.NET?
There is no way to do that with local variables. For

other publicfields, properties or methods have a look at the thread above this one.
--
Herfried K. Wagner
MVP VB Classic, VB.NET
<http://www.mvps.org/dotnet>
.

Nov 20 '05 #5

P: n/a
Hi Tino,

Based on my understanding, what you want to do is to access an
variable(Var2) by using another variable(Var1)'s value., which is a name
string.

I think this feature is usually supported by scripting programming
language, i.e. the language will execute code line one by one.
Implementing such a feature is resource-consuming and can cause performance
hit, so compiled languages like C/C++,VB, VB.NET and etc. never supported
the feature.
In such languages, compiler usually does not maintain variable names in the
executables so identifying a variable though a string name is not feasible.

Some controls (not the language) themselves maintain a name so they can be
identified using a name string, like for Controls in VB.

In .NET if you just want to identify a field (not local variables) you can
achieve that by using the reflection as Ken said. You may refer the article
in MSDN.
Dynamically Loading and Using Types
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpcondynamicallyloadingusingtypes.asp

If you simply want to bind two variables together so changing one will
cause the other to change as well you can use a reference type (class) to
encapsulate the value.

Can you tell me what do you want to do in the project?
I think there may be a better solution for you.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.