Passing Variable Name to a Function

B

Bob Howard

I have need to pass a variable name (to a function) which is actually a
string-type argument (or possibly a variant-type argument) that itself
contains the *NAME* of the variable I'm really interested in.

My application has a series of global variables where, at times, I need
access to their values from either a query or within the recordsource in a
control on a form or report. I could implement a function for each global
variable (to return its value) --- but I would prefer to "generalize" this
and have a common function that is capable of returning the value of any of
these global variables.

An example might be my global variable named gblProcessRouter. I want to
implement a function to return the value of gblProcessRouter as I refer to
its value in a query. Within a calculated field in the query, I want to
execute a function specifying something like:

getVariableValue("gblProcessRouter")

to return the value of gblProcessRouter.

What do I substitute for the ???????? to accomplish this?

Function getVariableValue(Variable_Name as String)
getVariableValue = ????????
End Function


Thanks in advance!

Bob (@Martureo.Org)
 
P

Peter R. Fletcher

I don't think that it's possible to do this for the general case. One
would think that the Eval() Function might work, but it does not
handle variables - only constant values and Functions. You could, of
course, write a Function with a Case statement for each of the names
of your global variables, setting the return value of the Function to
the value of that variable, but you would need to remember to add a
Case for each additional global variable. If you really need lots of
global variables (and I wonder whether what you are doing might be
better done another way), you could create a Table for them, with name
and value fields, and access them in a generic way through the Table.

I have need to pass a variable name (to a function) which is actually a
string-type argument (or possibly a variant-type argument) that itself
contains the *NAME* of the variable I'm really interested in.

My application has a series of global variables where, at times, I need
access to their values from either a query or within the recordsource in a
control on a form or report. I could implement a function for each global
variable (to return its value) --- but I would prefer to "generalize" this
and have a common function that is capable of returning the value of any of
these global variables.

An example might be my global variable named gblProcessRouter. I want to
implement a function to return the value of gblProcessRouter as I refer to
its value in a query. Within a calculated field in the query, I want to
execute a function specifying something like:

getVariableValue("gblProcessRouter")

to return the value of gblProcessRouter.

What do I substitute for the ???????? to accomplish this?

Function getVariableValue(Variable_Name as String)
getVariableValue = ????????
End Function


Thanks in advance!

Bob (@Martureo.Org)


Please respond to the Newsgroup, so that others may benefit from the exchange.
Peter R. Fletcher
 

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