Solved

Storing Information in a Scripting Dictionary

Posted on 2013-06-20
4
381 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

685 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