Solved

Storing Information in a Scripting Dictionary

Posted on 2013-06-20
4
358 Views
Last Modified: 2013-06-22
Hi All

I am using a scripting dictionary to store information e.g. captions for userforms.  This allows me to populate the userforms with text from outside the VBA project which I find convenient.

My question relates to best practice for scripting dictionary use..

Say, for arguments sake, I have 100 user forms and 1000s of captions.  And lets assume the userforms are opened and closed frequently.  And lets also assume that the information for each userform comes from a different source...

Should I set the scripting dictionary to Nothing after each instance of its use?

Or, is it ok to let the dictionary grow? (it can't grow indefinitely as its size can't exceed that of the combined information sources).

If killing off the scripting dictionary is not required, then should I load everything at once (e.g. when the document loads) or add to the dictionary bit by bit (e.g. on an as needed basis as each form is used)?

Would it be better to use 1 large dictionary or several small ones (assuming I don't need to set it to nothing after each use).

I guess, in a nutshell, I'd like to know the pros and cons of keeping the dictionary in memory (real impact, ways to avoid any detrimental impact?) versus continually loading and setting to nothing... what's more efficient??

I have more questions, but they may become irrelevant depending on the answers to the above.

Cheers,
0
Comment
Question by:DrTribos
  • 2
  • 2
4 Comments
 
LVL 59

Assisted Solution

by:Chris Bottomley
Chris Bottomley earned 500 total points
ID: 39264930
Leaving out the fact that the pc is always limited by disc/memory it takes processing to create objects therefore since you talk in terms of "after each instance of its use" this implies that the data in the dictionary has a limited 'life' and that you grow it for convenience.  This being so then try the removeall method to reset the dictionary back to 'new' and leave the dictionary object otherwise as is.

Chris
0
 
LVL 15

Author Comment

by:DrTribos
ID: 39267379
Hi Chris

Long time no see! I think you make a good point and I always like a third option.  

Some of the data would be used more than other data, and I think keeping the dictionary alive will make some of the code simpler... but instead of emptying the object what do you think of the idea of removing certain keys(?) and their associated values for data that is less used?

Or would it be better to have several empty dictionaries; all ready to be used with their specific type of data?  

What would bog the system down more - 1 big and full dictionary or a bunch of empty dictionaries?

From a purists view of programming:
Is it bad to keep an object like a dictionary alive?
Should I take active steps to minimize the size of the dictionary?
At what point would size become an issue?

Cheers, S
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 500 total points
ID: 39267598
I stress I am no expert in these matters but multiple dictionaries have to be harder on the system albeit overall trivial.  I do not believe size of a dictionary is particularly significant either but although i've used some huge ones ... yours could be bigger <g>.  At the end of the day I am sure that with sensible use of one or more dictionaries the limitations are going to be resource based and therefore unless using a dictionary for each individual key it is my experience that you can do pretty much whatever you want.

That said, if some data will be used more others then does it make sense to have a few dictionaries to cover the scope of data and clear them individually before re-use?

Note underlying my preference to reset or use multiple dictionaries is that sometimes outside of my knowledge I  am always afraid a duplicate key will exist and be missed or overwrite a required key and hence resetting periodically simply appeals to my fears.

Chris
0
 
LVL 15

Author Closing Comment

by:DrTribos
ID: 39267964
Thanks for your thoughts Chris
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you how to use shortcut menus in the Access run-time environment.
No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question