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

Eval() / Execute() - not in VBA?

Status
Not open for further replies.

jgillin

Programmer
Oct 22, 2003
82
US
Hi,
From what I can tell VBA doesn't have the Eval() or Execute() functions that VBScript has. Does anyone know why? (security concerns?). Is there any way to do runtime evaluation with VBA. I've noticed that the WSH has Eval() and ExecuteStatement() functions. Can we count on the user having the Windows Script Host these days (Is it packaged with Windows XP and turned on by default?).
I find these types of functions extremely useful. Please drop a note if you have found a solution to using runtime execution of statements.
 
Not sure it is exactly what you want but [ ] around a statement should evaluate it so

[TheRange]

will return the value for the named range "TheRange"

Rgds, Geoff

"Errors have been made....Others will be blamed"

Please read FAQ222-2244 before you ask a question
 
Actually I don't think this is what I was looking for.
I'm working in PowerPoint. What I want to do doesn't have anything specific related to PowerPoint, but simply evaluating the value of a variable from a dynamically built string:
Let's say I have 8 variables
var1, var2, var3, var4, var5, var6, var7, var8

In VBScript you can do this:
For i = 1 To 8
temp = Eval("var") & i
'' do something with temp
Next

Also, Execute() is similar, but dynamically executes an entire statement, like this:
Execute("var" & i & "=" & someMethod(i))

VBA simply doesn't have these functions, but I was wondering if anyone has found a good workaround. I think the reason they left these out was for security reasons (who knows).
Does anyone have any suggestions?
 
?Use an array?

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first
'If we're supposed to work in Hex, why have we only got A fingers?'
Essex Steam UK for steam enthusiasts
 
You may consider a VBA.Collection or a Scripting.Dictionary object.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
hi Johnwm,
good point
I guess I can store references to my objects in an array and then use them from there.
Thx
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top