Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Is it OK to store data globally?

Posted on 2004-04-08
7
Medium Priority
?
207 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 800 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

715 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