Solved

Is it OK to store data globally?

Posted on 2004-04-08
7
182 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
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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

773 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