Solved

Is it OK to store data globally?

Posted on 2004-04-08
7
191 Views
Last Modified: 2010-05-02
I have a VB6 (SQL 2000) app that has a lot of "preferences" that need to be available througout the use of the program.

What I have now is a preferences class that is created and filled when it is needed - then destroyed.

This is called alot throughout normal use.  

What is an acceptable way to store these values for the life of the app?  I would like to cut out some database traffic and only get these values if they have changed.  The values are only related to the running instance of the app so I dont need to worry about other users changing values.

I was considering using a global instance of the prefernces class? Is this bad practice?
0
Comment
Question by:tmorita
[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
7 Comments
 
LVL 18

Expert Comment

by:Sethi
ID: 10788704
No it wont be a bad practice. Infact it would be a better practice as it will reduce the time to create and destroy the class.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 10788948
What do you mean by "a global instance of the preference class"?
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 10789179
>> I was considering using a global instance of the prefernces class? Is this bad practice?

Siskel and Ebert give it two thumbs up. :]

It's fine to use a Class Module to encapsulate settings IMO. If you do decide to, declare your variables as private and use property subs to Get/Let. This'll keep the variables out of the object's interface and allow you to update the private variables within the Get/Let sub before returning their values. Because of this, you can avoid exposing additional properties/methods to the object's interface when you just need to get updated values.
0
Industry Leaders: 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!

 
LVL 27

Expert Comment

by:Dabas
ID: 10793951
Hi tmorita:
I would add a .bas module to your program with Global variables.
I agree with Sethi, it is not bad practice

Dabas
0
 

Author Comment

by:tmorita
ID: 10794927

>>What do you mean by "a global instance of the preference class"?

I already have a class with private variables.  The way it works now I declare/create/use/destroy this class all over the program to access these preferences.

I could create this class globally - once when the program opens - and use it thoughout the program.  

Instead of creating a module with global variables. (same thing really?)
0
 
LVL 27

Expert Comment

by:Dabas
ID: 10794945
tmorita:
> same thing really
Nearly. Yes
I have used both ways. It depends on if and how you want to reuse the class/module

Your original question is:
Is it OK to store data globally?
Answer is Yes.

Dabas
0
 
LVL 17

Accepted Solution

by:
zzzzzooc earned 200 total points
ID: 10795027
>> I already have a class with private variables.  The way it works now I declare/create/use/destroy this class all over the program to access these preferences.

You might as well keep the class the entire duration of your app since destroying it constantly isn't any better. If there's anything within the class that uses a lot of resources, you can place that in a seperate class and destroy it or destroy it within the current one. If there isn't, there's not much reason to support desroying it.
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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

726 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