|
|
 |
| Excel VBA Discuss using VBA for Excel programming. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Excel VBA section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

November 10th, 2006, 11:28 AM
|
|
Registered User
|
|
Join Date: Nov 2006
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
dynamic variable/object names
Hi,
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
|

November 13th, 2006, 07:03 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Location: London, , United Kingdom.
Posts: 173
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
Maccas
|

November 13th, 2006, 07:11 AM
|
|
Registered User
|
|
Join Date: Nov 2006
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Yep, that was exactly what I was asking, thanks very much.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |