p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Excel VBA (http://p2p.wrox.com/forumdisplay.php?f=79)
-   -   dynamic variable/object names (http://p2p.wrox.com/showthread.php?t=50140)

TheBFJ November 10th, 2006 11:28 AM

dynamic variable/object names

I'm slowly getting my head round VBA, but one feature I make use of frequently in other languages is dynamically naming a variable or object. I understand that some of this functionality can be reproduced with named ranges but could someone please give me a straight answer to this question:

In VBA is there an equivelent function to javaScript's eval() function or Object access operator [], which will allow me to create a variable at runtime like this:

Dim someString & someNumber As Integer

Js equivalent var eval(someString + someNumber) //(ish I'm a bit out of practice)

VBA claims to be an OO environment so it seems this functionality must exist. This is more for my own understanding of the language rather than a practical problem so please no "just use a named range" answers.

Many thanks

maccas November 13th, 2006 07:03 AM

Hi there,

I'm not 100% sure I understand the question but I think you're asking if you can dynamically, at run-time, declare a variable with a name to be determined at run-time. If this is what you're asking after then I'm not aware of any such functionality.

I guess one work-around would be to declare a two part User Type variable which consisted of (to extend your original example) an integer property and a tag string property. This would then lend itself to holding the integer information in the integer part and the dynamic name in the tag placeholder. Of course this is only useful if you really need this sort of functionality as it is a bit clunky. I guess having learnt to write code in VBA I don't see the need for dynamic run-time variable names.

I'd be wary of any claims from VBA to be OO because it isn't. To be fair it does try and is not bad in most places but I wouldn't alway s expect to see generic OO functionality in VBA.


TheBFJ November 13th, 2006 07:11 AM

Yep, that was exactly what I was asking, thanks very much.

All times are GMT -4. The time now is 12:43 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.