473,326 Members | 2,110 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,326 software developers and data experts.

Does associative array exist in VBA?

Hi everybody,

I would like to access to one variable by an indirect mode. I would try
to explain myself:

I have like twelve variables and all of them are global scope.
The point is that I have a private method that depending of the value
of one of its params I have to access to one global variable or other
one.

I tried to access like
Me.["tot"+pParam]

but it doesnt work.

is it possible to do this in other way? or maybe it is impossible in
VBA...

Thanks very much in advance

Jose

Feb 13 '06 #1
7 11361
If you're doing what I thing you're doing, try this syntax:

Me.Controls("tot" & pParam)

--
Wayne Morgan
MS Access MVP
<jo**********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Hi everybody,

I would like to access to one variable by an indirect mode. I would try
to explain myself:

I have like twelve variables and all of them are global scope.
The point is that I have a private method that depending of the value
of one of its params I have to access to one global variable or other
one.

I tried to access like
Me.["tot"+pParam]

but it doesnt work.

is it possible to do this in other way? or maybe it is impossible in
VBA...

Thanks very much in advance

Jose

Feb 13 '06 #2
jo**********@gmail.com wrote in
news:11**********************@o13g2000cwo.googlegr oups.com:
I would like to access to one variable by an indirect mode. I
would try to explain myself:

I have like twelve variables and all of them are global scope.
The point is that I have a private method that depending of the
value of one of its params I have to access to one global variable
or other one.

I tried to access like
Me.["tot"+pParam]

but it doesnt work.

is it possible to do this in other way? or maybe it is impossible
in VBA...

Thanks very much in advance


Sounds like you've used naming conventions for controls using
numbers.

Your mistake is in using the wrong method for concatenating the
name. What you want is:

Me("tot" & pParam)

You'd use the & concatenation operator because you don't want to
propagate Nulls (the + concatenation operator propagates Nulls, so
that if pParam is Null (assuming it's a Variant and can be Null),
then you'd be passing Me(Null) which will generate an error.
Me("tot") will also generate an error if there's no control of that
name, but probably a less serious error).

I'm not at all sure what this has to do with arrays, though.

Also, It sounds like you're populating repeating data, which sounds
like a possible design error somewhere along the way. Now, I've done
exactly what you're describing in particular situations, but it's
something of a kludge, in my opinion, as it ties your code to
objects on a form having been named in a particular fashion.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Feb 13 '06 #3
Hi David,

I was mistaken, I am trying to that but not in Access, it is in Excel.

The sintax you said doesn't work either.

Should I try another one?

Thanks once again.

Feb 14 '06 #4
One thing I forgot, I tried to acces not to a control, it is just a
global variable.

I already changed the program but I would like to know if it is
possible to do that thing.

Thank you very much

Cheers!

Feb 14 '06 #5
Hi Wayne,

I was mistaken, I am trying to that but not in Access, it is in Excel.

The sintax you said doesn't work either.

Should I try another one?

Thanks once again.

Feb 14 '06 #6
Well, the syntax I gave didn't work because you're really using Excel.
Please try the Excel newsgroup, they'll be able to help you better.

--
Wayne Morgan
MS Access MVP
"YaKs" <jo**********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Hi Wayne,

I was mistaken, I am trying to that but not in Access, it is in Excel.

The sintax you said doesn't work either.

Should I try another one?

Thanks once again.

Feb 14 '06 #7
"YaKs" <jo**********@gmail.com> wrote in
news:11**********************@g47g2000cwa.googlegr oups.com:
Hi David,

I was mistaken, I am trying to that but not in Access, it is in
Excel.

The sintax you said doesn't work either.

Should I try another one?


Post your question in an Excel group.

In any event, I expect that if you're trying to concatenate a
variable name you need to use Eval().

But my guess is that you need to completely change your approach to
the problem. In Access, I would suggest a custom collection or an
array, but I don't know what Excel's variety of VBA supports.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Feb 14 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: maciej | last post by:
I got an array that consists of elements that are arrays also. Now I wish I could add an element to the middle of it. Let mi give you an example: array ( - array(1,15,apple), -...
6
by: mark4asp | last post by:
Suppose I have the following code. It functions to randomly select a city based upon the probabilities given by the key differences in the associative array. . Eg. because the key difference...
4
by: Robert | last post by:
I am curious why some people feel that Javascript doesn't have associative arrays. I got these definitions of associative arrays via goggle: Arrays in which the indices may be numbers or...
14
by: Yereth Jansen | last post by:
Hi all, I encountered a problem with looping through an associative array. All worked perfectly with the following code: for (var menuItem in this.menuItems) { doSomething(); } where...
47
by: VK | last post by:
Or why I just did myArray = "Computers" but myArray.length is showing 0. What a hey? There is a new trend to treat arrays and hashes as they were some variations of the same thing. But they...
35
by: VK | last post by:
Whatever you wanted to know about it but always were affraid to ask. <http://www.geocities.com/schools_ring/ArrayAndHash.html>
7
by: Robert Mark Bram | last post by:
Hi All! How do you get the length of an associative array? var my_cars= new Array() my_cars="Mustang"; my_cars="Station Wagon"; my_cars="SUV"; alert(my_cars.length);
13
by: Felix H. Dahlke | last post by:
Have been hacking on this for about an hour, so I thought that this effort was useless if noone would use it. The following code generally is a hack-example of the implementation of an associative...
2
by: dtra | last post by:
hi all i've got this application where a user selects tabs on the page, which then loads a different section onto another section of the page we currently have it working using ajax, but we...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...

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.