Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Create dynamic variable names?

Hi,

I have been looking everywhere on how to create dynamic variables in excel.
I want the same result as what the eval() function in JavaScript gives. ie.

a1 = new Array(10);
a1[0] = "hello";
alert(eval("a" + 1)[0]);

or

for(i = 0; i <=10; i++){
eval("a"+i) = i;}

Any help would be appreciated.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default Create dynamic variable names?


There's no way to do this is VB/VBA. It's just not a supported feature.

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


"J Kruger" wrote in message
m...
Hi,

I have been looking everywhere on how to create dynamic variables in

excel.
I want the same result as what the eval() function in JavaScript gives.

ie.

a1 = new Array(10);
a1[0] = "hello";
alert(eval("a" + 1)[0]);

or

for(i = 0; i <=10; i++){
eval("a"+i) = i;}

Any help would be appreciated.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Create dynamic variable names?

If you want to reference items/values via "names" created at runtime then
try using a Dictionary object.
Creating variable names at run-time (even when it's possible) is usually not
the best approach to a problem.

Tim.

"J Kruger" wrote in message
m...
Hi,

I have been looking everywhere on how to create dynamic variables in

excel.
I want the same result as what the eval() function in JavaScript gives.

ie.

a1 = new Array(10);
a1[0] = "hello";
alert(eval("a" + 1)[0]);

or

for(i = 0; i <=10; i++){
eval("a"+i) = i;}

Any help would be appreciated.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Create dynamic variable names?

Thanks.

The dictionary option unfortunately can only one value/reference per
key.
So you are stuck again with creating an array or variable for each key
to contain more than one value.
Then you must in any case again make dynamic arrays/variables.

I will keep suffering with VB until it becomes a REAL language.
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default Create dynamic variable names?

If you were to describe what you're trying to do I'm sure you will get at
least one viable suggestion which does not involve creating dynamic
variables. Even in languages where this is possible (eg.
javascript/vbscript) there are few occasions where it's really warranted.

Tim.


"J Kruger" wrote in message
om...
Thanks.

The dictionary option unfortunately can only one value/reference per
key.
So you are stuck again with creating an array or variable for each key
to contain more than one value.
Then you must in any case again make dynamic arrays/variables.

I will keep suffering with VB until it becomes a REAL language.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to replace one dynamic variable with another dynamic variable djreason Excel Worksheet Functions 8 September 11th 09 01:57 AM
Dynamic Worksheet Names HOOS77 Excel Discussion (Misc queries) 3 September 4th 07 10:24 PM
Dynamic scenarios - more than 2 variable using data tables in Exc Varghese Excel Discussion (Misc queries) 0 August 7th 06 03:16 PM
dynamic summed range based on a variable Bruce Excel Worksheet Functions 3 November 8th 05 02:45 AM
Dynamic Worksheet Names JClub Excel Worksheet Functions 1 January 10th 05 08:55 PM


All times are GMT +1. The time now is 07:15 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"