Solved

Is it OK to store data globally?

Posted on 2004-04-08
7
203 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…
Suggested Courses
Course of the Month6 days, 6 hours left to enroll

626 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