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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Literal vs Variable

Status
Not open for further replies.

mushin

Programmer
Oct 4, 2000
49
How do I distinquish between a variable (MyVar)
and a string literal named "MyVar" ????

To clarify, I am passing a string var to a sub proc
and if I do this :

myProc tmpMyVar
then the contents of the var are passed..BUT,

If I do this:

dim fieldName as String
fieldName = "MyVar"
myProc "tmp" & fieldName

then all that is passed is the literal string "tmpMyVar"

So how can I create my var name and pass it's contents,
not just it's name.....

I do this in other lanquages and am just not that familiar with VB !!!!

Any help would be appreciated.....
thx
 
You can probably use the Eval() function for this. Eval() takes a string argument and evaluates it as if it were an expression written in code. It returns either a string or a number.

One caveat: Passing Eval("tmpMyVar") isn't exactly the same as passing tmpMyVar. If you pass tmpMyVar using a ByRef parameter (the default), the called procedure can modify its value in the calling procedure. But if you pass Eval("tmpMyVar"), what's actually passed is a temporary "variable" used to hold the result of Eval(), so any changes made by the called procedure will not affect tmpMyVar. Rick Sprague
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top