473,763 Members | 2,375 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to make constants available for the whole application?

I need to make a set of constants to be available for the whole application.
Public const is confined to the form from which constants are declared.
Is there a way to declare once and all forms can access the constant values?
Thanks
Bill
Nov 21 '05
11 7785
Ross,

"Ross Presser" <rp******@NOSPA Mgmail.com.inva lid> schrieb:
My point was that associating the constants with the appropriate class
is a better option than putting them into a general module, not that
one is incapable of using a class like a dumping ground. Better tools
do not prevent poor design, they just provide and opportunity to do
things better than 'the way we've always done it'


I don't understand why you consider it a "better design" to create a class
that does nothing but group a bunch of constants together, even if they
are
semantically related, if there is no more substance to the class.

One step further, I fail to see the joy in a class that has no member or
private variables, only shared methods and constants. If I'm calling the
exact same function every time, and it has no internal state of any kind,
and I always have to feed it a full set of arguments, why should it
pretend
it's part of a class or an object?


That's what my concern is about. Classes are IMO a language feature used to
model entities, and thus not intended for /grouping/ objects (functions,
constants, ...) with a loose relationship.

However, I don't think that modules are the best possible solution because
they are automatically imported. I would prefer modules which need to be
imported explicitly or whose members do not always appear in IntelliSense.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #11
I was neccessarily talking about a class that contains only constants
(though that is not intrinically a problem), I was talking about
associating constants with an appropriate class rather than sticking
them in a general holding tank.

Simple example, Client Colors

Say we have an application and want to have all the forms use a given
color scheme (we want a specific one rather than use the Windows
scheme)

Instead of setting them on all the forms at design time (which will be
tedious to change when someone in marketing says, 'Oh! Puce is the new
black!"), we have a set of constants for the colors.
Where do we put them?

We can stick them in a module, or
We can place them in, say, a ClientConfig class along with the default
screen height and width and whatever other values that we reckon are
appropriate for Client Configuration.

Does it have any functionality included? Perhaps not, at first; we have
a fixed set of colors that the user is not allowed to change.

But if at some point we decide to allow the users to customize the
client colors we can add that functionality to this class and with very
little (if any) change to the application code we now have a client
with customizable colors.

I do not see that a module is 'sematically more correct' or even
semantically anything. A module started off life as ' the source code
for a program', evolved into 'a compilation unit' and now to me seems
like a vermiform source file. I personally think they are not useful
but that's a free opinion (and worth every penny)

My comments boil down to

1) A single large source file (be it class or module) for holding all
the constants that may need global scope, is a bad thing.

2) On anecdotal evidence, one a StdDef.bas gets created, everything
gets dumped in there. Almost by reflex. We're short on time, don't
have a chance to work through where a new 'something' should be put.
Stick it here and we'll get back to it later... promise.

3) Constants are given a global scope when they need to used in more
than one place but they can be usually said to 'belong' to a specific
piece of functionality and should be associated with that.

e.g.
ClientConfig.SC REEN_WIDTH
MyApplication.A PP_NAME

4) Sort of OT; Low level constants and declares should not be visble
to the application code at all.
P/invoke delcarations, OS constants (say, WS_EX_TOOLWINDO W or
SIZE_MINIMIZED) should be wrapped by a class and that functionality
invoked through the class.
This removes the need for them to be in the global namespace at all.

Alan.

Nov 21 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
4502
by: 2obvious | last post by:
I've been trying to create read-only global variables by creating constants (Const) in my global.asa, but I can't seem to reference them. Sticking them in an include works fine, but it seems more structurally sound to use Application_OnStart. Am I attempting the impossible, and if so, why?
12
3304
by: Steven T. Hatton | last post by:
This is something I've been looking at because it is central to a currently broken part of the KDevelop new application wizard. I'm not complaining about it being broken, It's a CVS images. Such things happen. The whole subsystem is going through radical changes. I don't really want to say what I think of the code just yet. That would influence the opinions of others, and I really want to know how other people view these things,...
2
2779
by: RD | last post by:
My application contains several Classes & Forms . From the Login form I will get the User ID and Password for the SqlConnection. I established the connection through another class and I can get it in the Login form. In another form , say Employee form , I want to save the Employee details to the Employee table. But when I tried to use connection which is already opened I couldn't get it.
7
2562
by: Don Wash | last post by:
Hi There! I'm trying to define constants so that I can refer those constants from any page of my ASP.NET website. I know I can use <appSettings> in web.config XML file but I don't want to parse and read the whole XML document everytime a page is requested. In classic ASP, I used Include files and define constants using Const keyword so that every page that has been included the file can refer the constants.
2
1611
by: Steve | last post by:
I am developing an asp.net 2.0 application and have come across the dilemma of how to store constant values, which change infrequently. The website will have tens of thousands of visitors every day. Obviously there is the application object route. However, because of the new feature of sql server cache invalidation, would it not be best just to create a normal data access layer which can retrieve a datatable containing the constants...
3
2555
by: Lenonardo | last post by:
Can anyone tell me how I refer to Excel constants when using late binding. I've tried searching the Excel.application interface but can't find any reference in the hierarchy to an object that holds constants (such as XlPattern.XL.....). This must be possible (e.g. as with a typelib) but I can't track it down. Any help appreciated.
34
3391
by: newsposter0123 | last post by:
The code block below initialized a r/w variable (usually .bss) to the value of pi. One, of many, problem is any linked compilation unit may change the global variable. Adjusting // rodata const long double const_pi=0.0; lines to // rodata
10
1552
by: Paul | last post by:
Hi all, All of the classes in my DAL are static, with constants defining the stored procedures and parameters. I've been having some problems with my site which makes me wonder if there's a thread safety issue. Are consts thread safe? Would the following example create any thread safety issues? Would you recommend using static readonly members instead of constants?
36
2123
by: anon.asdf | last post by:
Hello! Can the proprocessor make conditional decisions. Here's an example of the functionality (not standard C!) #define PUT_BYTE(const_index, val) \ #preprocessor_if (const_index == 0) \ ({ *(77) = (val); }) \ #preprocessor_else_if (const_index == 1) \ ({ *(99) = (val); }) \
0
9386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9998
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9938
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9822
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7366
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3523
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.