473,396 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Using content of variable

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
5 1531
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
* "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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dany P. Wu | last post by:
Hi everyone, I've finally figured out what I actually want to do with my website, let's hope this time I can explain it better. The opening page of the website has a bunch of links that look...
1
by: jon | last post by:
I would like to use the variable that the javascript creates as it parses the URL and be able to use this variable in other links on the same page. notice how link to page 2 has the token but the...
3
by: J Smith | last post by:
I'm making a website where each page has the same design, obviously its a bad idea to put the same code/html in each page so what is the best way to do this? What I'm doing at the moment is...
8
by: Kathleen Dollard | last post by:
Hi, Oleg's answer about attribute value templates led me to look back at a different problem, and wonder if someone else had solved it. I want to output an ASP.NET page. Thus I need to output...
6
by: ransoma22 | last post by:
I developing an application that receive SMS from a connected GSM handphone, e.g Siemens M55, Nokia 6230,etc through the data cable. The application(VB.NET) will receive the SMS automatically,...
23
by: lwoods | last post by:
I am trying to pass some info to another page on my site. I set "session_start()" in page 1, assign a session variable to a value, then execute a "header('Location: ....')." But on the target...
21
by: comp.lang.tcl | last post by:
set php {<? print_r("Hello World"); ?>} puts $php; # PRINTS OUT <? print_r("Hello World"); ?> puts When I try this within TCL I get the following error:
5
by: woodced | last post by:
This is driving me a bit crazy now. I've got a page with 3 columns. However the 3 columns are divided up into horizontal rows. In the central column of hte horizontal row the content can be of...
0
by: anu b | last post by:
Now i am sending email to my friend using session variable... but my code is as below private bool SendEmail(string email) { try {
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.