How does VBA Store Arrays

chazz

Board Regular
Joined
Jul 24, 2006
Messages
70
I put an array in my code last night. Then I noticed that, after I shut Excel down an restarted it, the array values had not been lost.

Is the array stored in permanent memory? I didn't try shutting the machine down, to see if it survived that.

??
 
I appreciate all the help, but...

nothing to do with how an array is stored? I ASKED how an array was stored -- it's right there in my first post.

My password generator works famously. But I got curious about how the program stores the array, so I asked about it.

Now I'm curious how to store stuff in the registry, but I guess I'll just go search msdn....

thanks all, and have a great weekend.

And never forget 9/11.
 
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
chazz,

I don't know the answer but you have my sympathy. At least I can read and understand the question. LOL. Hang in there.

Dufus
 
Upvote 0
Thanks.

Actually the routine raised the question about how ARRAYS store DATA, whether somewhere in permament memory or not --and that is what my post is about.

It is not permanent.

It will be cleared from the memory when the routine finshes unless declared as a global variable.

Rnd function returns the same when you refresh it without Randomize statement.

Hi chazz,

The above actually does answer your question.
1. Arrays are loaded into memory when the routine creates them.
2. When the routine finishes, the array is flushed from memory, unless (as Jindon pointed out) you change the scope of the array to a Global. Then it stays in memory until all routines stop executing.
3. You saw the same array values because Rnd() always starts with the same seed value unless you add the RANDOMIZE line.
4. You can retain array values by writing them to the registry, or by writing them to a range on a worksheet. Then you can grab those values again if you need them.

Hope that helps
Denis
 
Upvote 0
SydneyGeek,

Thanks for the follow up, however if OP tried my first post, we would realise.

He is only asking about the scope of variable to me...

Like Norie stated, this has nothing to do with "HOW ARRAY IS STORED".
 
Upvote 0
You asked the wrong question if your goal was to solve your problem. Others rightly focused on the real issue. But clearly you think focusing on how arrays are allocated will help solve your problem. So, here's something to think about.

Consider a N dimensional matrix, declared as Dim X (dimension-1, dimension-2, ..., dimension-N)

The stack contains a pointer(*) to the Nth dimension, which is allocated as a 1-D vector of pointers.

Each pointer references a one dimensional vector that represents the N-1th dimension, each element of which is a pointer.

Each pointer in the N-1th dimension is also a pointer that points to a 1D array of pointers that represent the N-2nd dimension.

The process continues all the way down to the 2nd dimension.

The 2nd dimension consists of a 1-D vector of pointers, each of which points to a 1D vector of the declared data type of the matrix.

Now, you tell us. How does that help solve your problem?

(*) I would not be surprised if the implementation uses handles rather than pointers. If I were designing the system, I would almost certainly use handles.

I appreciate all the help, but...

nothing to do with how an array is stored? I ASKED how an array was stored -- it's right there in my first post.

My password generator works famously. But I got curious about how the program stores the array, so I asked about it.

Now I'm curious how to store stuff in the registry, but I guess I'll just go search msdn....

thanks all, and have a great weekend.

And never forget 9/11.
 
Upvote 0
chazz,

I don't know the answer but you have my sympathy. At least I can read and understand the question.

Dufus
Really? Maybe, you can tell the experts how resolving the OP's curiosity about how arrays are allocated will solve hir *real* problem about how the generated RVs are the same.
 
Upvote 0
Greetings Mr. Mehta,
Really? Maybe, you can tell the experts how resolving the OP's curiosity about how arrays are allocated will solve hir *real* problem about how the generated RVs are the same.
Jindon said:
try add one line before For Loop
Randomize
after OP revealed that he was using the rand function in the macro. After it clicked that OP didn't get the implication SydneyGeek said:
3. You saw the same array values because Rnd() always starts with the same seed value unless you add the RANDOMIZE line.
I think that is sufficient cause for an OP who is not an expert to feel a little frustrated but, who am I to speak for them? I think this is not a statement about level of expertise but about how difficult it is to ask the right question when you don't know what you don't know if you know what I mean... I probably found it easier to understand the question (even if I didn't know the answer) because I'm closer in experience to the OP than to an Excel MVP. More importantly, both sides persevered and the answer was revealed in spite of my perhaps inflamatory remark.

I remain respectfully,
Dufus
 
Upvote 0
Dufus,

I didn't feel like the OP is such inexpert according to his reply to my posts.

But I'm really curious to know how good is his "Famous Pasword generator", without the knowlege of the nature of Rnd function and array variable.
 
Upvote 0
Jindon. :)

This is ONTOPIC. At least I think it is.

RANDOMIZE
A RND joke here:

The reason I broke up with my girlfriend...

She said our finances were getting tight and I would have to give up the BEER.

After 2 weeks of NO BEER I found out she spent:
$80 to get her hair done
$40 for a manicure
$35 for a peidicure
$120 for a gym membership
$320 on new clothes

When I confronted her about the spending, she said she had to spend
this money to look good for me.
I said that's what the BEER was for.
I don't think she's coming back.
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,541
Members
449,089
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top