Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

use a variable by reference, address ? like "&" in foxpro

Status
Not open for further replies.

thomascd

Programmer
Mar 20, 2002
29
0
0
GB
HOw to use a variable by reference in VB like one would do using the operator '&' in visual foxpro or other languages ?
for example

m1="my value"

m2="m1"

msgbox (&m2) 'should display "my value" and not "m1"
 
thomascd,

All you need to do is leave the quotes out of your second assignment statement, and then reference the variable directly in your "msgbox" line:

Code:
m1="my value"

m2=m1

msgbox m2  'WILL display "my value" and not "m1"

There is no such thing as explicit variable de-referencing in VB (which is clearly what you're used to). In a UNIX script, for example, you'd use "$m2" to display the value of the variable "m2",or under MPE "!m2" to get the same result. Interpreted languages need an explicit dereferencing "mark", largely because variables are not declared. VB keeps track of its variables (even if they aren't explicitly declared - but don't try that at home, kids!) and so you don't have to say to the language "here comes a variable".

Anyhow, enough of my rambling. Try it and see how you go!

Regards,
SmallCraig[upsidedown]
 
SmallCraig - The macro operator (&) in FOXPRO is quite powerful in that you make the assignment at run time rather then as per your example, at design time. Although VB does not provide instrinsic support for variable dereferencing, it can be done in VB by using the scripting capabilities, or you can go directly into the TypeLib Interface and get the job done. The Script wrappers are somewhat easier to use.

If you include the Windows Host Script Object Model in the project, then you can take advantage of the .Eval method of the ScriptControl object. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
CajunCenturion,

Thanks for the extra knowledge. But I can't quite imagine a situation where I'd actually want to do that. Can you give an example of a time when that would be required?

Always interested in exploiting someone else's experience!

SmallCraig[upsidedown]
 
SmallCraig,
Just do an appropriate keyword search in this forum, and you will find that this question comes up repeatedly for a number of reasons.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top