Solved

Storing Information in a Scripting Dictionary

Posted on 2013-06-20
4
321 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
Comment Utility
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 14

Author Comment

by:DrTribos
Comment Utility
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
Comment Utility
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 14

Author Closing Comment

by:DrTribos
Comment Utility
Thanks for your thoughts Chris
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now