?
Solved

Storing Information in a Scripting Dictionary

Posted on 2013-06-20
4
Medium Priority
?
396 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 59

Assisted Solution

by:Chris Bottomley
Chris Bottomley earned 2000 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 2000 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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Ever wonder what it's like to get hit by ransomware? "Tom" gives you all the dirty details first-hand – and conveys the hard lessons his company learned in the aftermath.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

777 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