Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 10th, 2006, 11:28 AM
Registered User
 
Join Date: Nov 2006
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
Reply With Quote
  #2 (permalink)  
Old November 13th, 2006, 07:03 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: London, , United Kingdom.
Posts: 173
Thanks: 0
Thanked 3 Times in 3 Posts
Default

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

Reply With Quote
  #3 (permalink)  
Old November 13th, 2006, 07:11 AM
Registered User
 
Join Date: Nov 2006
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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



Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic column names in crystal reports pankaj_daga Crystal Reports 3 January 19th, 2009 02:55 AM
generate variable names dinamycally gcorcuera Classic ASP Basics 7 May 21st, 2007 09:53 AM
Resolution of property names on window object AGS BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 3 August 5th, 2006 11:50 AM
Problem with variable names shenku Javascript 2 May 6th, 2005 03:46 PM
Retrieving Dynamic Field Names tdaustin Classic ASP Basics 4 January 12th, 2004 11:10 AM



All times are GMT -4. The time now is 09:42 AM.


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