'Eval' trials and tribulations

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need a routine that displays a variable's contents and allows the value to be changed. I tried using 'Eval' but Acvcess refuses to find the variable I specify. Is this possible

My attempt
Dim x as string, y as strin
x=Inputbox("Enter variable"
Msgbox eval(x) <========= this fail
y=Inputbox("Enter new value"
eval(x) = y
 
Hi David,

Access's debugging tools let you do this without writing any code. Just
set a breakpoint and do things like this in the Immediate pane (debug
window):

?x
blah
x = "new value"
?x
new value

Or use the Watch facility to track the value of a variable as your code
changes it.

If you're thinking of including this sort of thing in the normal
operation of an application, IMHO you're wrong.
 
We don't have what FoxPro called "macro substitution"

However, any value from a collection can be resolved at runtime.

strWhatForm = InputBox("Enter form name")
strWhatField = InputBox("Enter what contorl ")

msgbox "the value is " & forms(strWhatForm)(strWhatField)

Since any control on a form can be resolved via a string var...I have NEVER
needed to resolve variables at runtime.

Most modern languages don't allow macro substitution...but no big deal...as
you can use custom collections.

dim myValueList as new Collection

...... code here to load up the customlist "MyValueLIst"

x=Inputbox("Enter variable")
Msgbox "The value of var = " & MyValueList(x)

You likely should explain what you are trying to do...not ask how to ref a
variable with a variable, as the above examples show that you don't need to
do this in ms-access.

What exactly are you trying to do that can't be done with a collection?
(either via the built in ones...or your own custom one).
 
David,

I copy/pasted your sample code into an Access Module and
ran it. I ran fine until the last eval(x) = y.

It prompted to set the value of x, it prompted to set the
value of y. As for the last line, did you perhaps intend
to set x = eval(y) ????

respectfully,

Bob
-----Original Message-----
I need a routine that displays a variable's contents and
allows the value to be changed. I tried using 'Eval' but
Acvcess refuses to find the variable I specify. Is this
possible?
 
I have a system where everything is controlled by security tables keyed
off the userid of the logged on person. I need to change the user variable
to different users to test out the security features.

It does not make sense to change the variable name? Why not just change the
"value" of a variable? This in no way seems to hint that you need runtime
resolution of a variable name. Further, if that data is in tables...then
again all values in a table (recordset collection) can be resolved again at
runtime. So, up to this point...I can not see why having some security
tables controlled by a userID would requite runtime-resolution of variable
names? (you may have some reason...but the simple fact of using security
tables keyed by some user would NOT in any way support your argument). You
are going to have to show an specific example.
I also have many other potential uses for such a tool.

Ok, that may be the case!...but as mentioned, virtually all data, and
properties of collections (built in, or your own custom) can be resolved at
runtime...so, I am still at a loss here.
I'd rather not use debug to do this as I find it a pain to use.

Sure...but no one is suggesting that you do this. If you data is in tables
(as you state), or you store values in collections...both as mentioned can
be resolved at runtime (ie: a value in a value can be used to resolve what
you want). You certainly can't resolve variables in VB at runtime...but as
mentioned developers don't miss this feature since we don't write and design
software that has such a requirement.
 
Back
Top