473,383 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

set variable value when variable name is stored in array

dsatino
393 256MB
I'm sure I've actually done this before, so why I can't figure this out now is annoying. I'm hoping someone can spark my memory here.

Basically, I have 54 variable names stored in an array. I want to set the values of the variable values using the array as the name reference.

In other words, instead of:
x=1

I want to set x by referring to it's location in the array.
I tried:
myarray(0,0)=1

Unfortunately, this just changes the variable name that I have stored in the array to 1. Ha! Not quite what I want.

Any help would be greatly appreciated.
Aug 9 '10 #1
9 3276
ADezii
8,834 Expert 8TB
I cannot understand why you would use a Multi-Dimensional Array, but in any case, in the following example, the Value of X would be equal to whatever is stored in the 3rd and 6th Elements at the intersection of the 1st and 2nd Dimension of the Array MyArray (assuming the Array is dimensioned starting at 0):
Expand|Select|Wrap|Line Numbers
  1. X = MyArray(2, 5)
Aug 9 '10 #2
NeoPa
32,556 Expert Mod 16PB
I looked at using Eval(), but that doesn't seem to do the business.

As variables are not generally objects either, even populating your array with object references beforehand (in place of the simple names of the variables) would not work for you. Sorry. I'm stumped.

Much easier in C derivative languages of course.
Aug 10 '10 #3
ADezii
8,834 Expert 8TB
Sorry that I misread this Thread. Why not simply have a Hidden Lookup Table with Strings representing Variable Names along with/without associated Values? Setting/Retrieving Values would be a simple task. If you don't mind me asking, what is the purpose of this?
Aug 10 '10 #4
dsatino
393 256MB
The purpose, originally, was to set variables without having to type them. There are about 60 of them that get set at various stages of 3 nested loops. Depending on user inputs some may not even be used. The game plan to have it all neat and organized so that each variable would have a set location in the array that would align with the loop variables and hence, set the correct variable at the correct time.

However, after coming in this morning with a fresh cup of coffee and a few hours of not trying to force this to work, it occurred to me that the array could just as easily store the variable values. (isn't that what arrays are for anyway? duh.)

In any case, thanks all for your time and efforts as usual.

P.S. I did find a previous project where I thought I was doing this and it turns out that I was calling functions. I also found documentation that stated that what I was trying to do was not possible with the VBA version of eval().
Aug 10 '10 #5
NeoPa
32,556 Expert Mod 16PB
This may seem somewhat radical, but have you considered using the array instead of the variables completely? It may not be an appropriate solution across the board, so only you can determine how much sense is in that.
Aug 10 '10 #6
dsatino
393 256MB
Yup, that's exactly what I meant when I said I would use the array to store the variable values instead of the variable names. So the variables themselves will cease to exist and the array will store all values with each specific location in the array relating to a certain point in the nested loops.
Aug 10 '10 #7
NeoPa
32,556 Expert Mod 16PB
Oh I see. Sorry. I misunderstood you.

Good idea though :D
Aug 10 '10 #8
Is this what you need to do?

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.   var a = "test"
  3.   var arr = new Array("a");
  4.   alert(window[arr [0]]);
  5.   window[arr [0]] = 'value changed';
  6.   alert(window[arr [0]]);
  7. </script>
  8.  
Aug 10 '10 #9
NeoPa
32,556 Expert Mod 16PB
I'm afraid Access uses VBA exclusively. Javascript couldn't even run within Access.
Aug 12 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Mike | last post by:
Is there any way I can use a function to create a variable and assign a value to it? I have a Perl script that returns some LDAP information: sn=Shore givenname=Mike logintime=20041008153445Z...
11
by: Pete Mahoney | last post by:
I am currently working on an ASP page where I create a lot of different check boxes. I have some checkboxes that are Windows platforms and some that are solaris platforms. I want a control...
2
by: C Gillespie | last post by:
Dear All, I have 2 arrays var A1 = new Array(); A1 ="Y2"; var B1 = new Array(); B1 ="Y1"; B1 ="sink";
4
by: Lucas Sain | last post by:
Hi, I think thta for this I have to use reflection... but I'm not shure. How can I find/get an object at runtime by looking for its name that is stored in a variable. For example: I have a...
10
by: Blaxer | last post by:
There is probably a really easy way to do this, so please forgive me but I would like to set the value of a variable from a variable, an example would be... function Calculate_Something(ByVal...
7
by: John Smith | last post by:
Hello, I have a simple question, I have a vb.net form with several buttons. If I store the name of a button in a variable.. Dim TheName as string TheName = ...
0
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I want to display a progress bar on my web page. I have this code for progress bar in javascript in my web page. I have a button on the web page, if someone clicks that button...
6
MrPickle
by: MrPickle | last post by:
I have a struct like so defined like so: //vector3.h struct Vector3 { float x, y, z; Vector3(); Vector3(float _x, float _y, float _z); Vector3(const Vector3 &v); };
5
by: parry2k | last post by:
I have one view with 3 fields like the view name is myview and it has following sql statement. select fn,ln,city from tablea I created a function like below:- create function myfun(in t...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.