473,657 Members | 2,496 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Where is best place to define hard coded values?

If I have many hard coded values such as file paths, file names, timeouts,
etc, where is the best place to define them? Meaning, in the case something
needs changing for example, rather than running down all the subs or
functions that may contain these values, I'd like one place to change them
and have that changed reflected in the subs or functions that use those
values. I'd like to avoid globals; keeping the values private to only those
subs or functions using them.

Thanks,
Brett
Nov 21 '05 #1
10 2832
Hi,

I would make a variable that is private to the class or form.
That way all the sub routines and functions can use it. It wont be
accessable out side the form or class.

Ken
-----------
"Brett" <no@spam.net> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
If I have many hard coded values such as file paths, file names, timeouts,
etc, where is the best place to define them? Meaning, in the case something
needs changing for example, rather than running down all the subs or
functions that may contain these values, I'd like one place to change them
and have that changed reflected in the subs or functions that use those
values. I'd like to avoid globals; keeping the values private to only those
subs or functions using them.

Thanks,
Brett

Nov 21 '05 #2
Nice. Thanks.

Brett
"Ken Tucker [MVP]" <vb***@bellsout h.net> wrote in message
news:Op******** *******@TK2MSFT NGP15.phx.gbl.. .
Hi,

I would make a variable that is private to the class or form.
That way all the sub routines and functions can use it. It wont be
accessable out side the form or class.

Ken
-----------
"Brett" <no@spam.net> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
If I have many hard coded values such as file paths, file names, timeouts,
etc, where is the best place to define them? Meaning, in the case
something
needs changing for example, rather than running down all the subs or
functions that may contain these values, I'd like one place to change them
and have that changed reflected in the subs or functions that use those
values. I'd like to avoid globals; keeping the values private to only
those
subs or functions using them.

Thanks,
Brett

Nov 21 '05 #3
There will be some shared variables mixed in. Meaning, I'll define
variables in one class that will also be used in other classes or forms.
For those shared variables, should I just create a class that only houses
them? This provides one place to change them and have those changes cascade
through out forms/classes that are using them.

Brett

"Ken Tucker [MVP]" <vb***@bellsout h.net> wrote in message
news:Op******** *******@TK2MSFT NGP15.phx.gbl.. .
Hi,

I would make a variable that is private to the class or form.
That way all the sub routines and functions can use it. It wont be
accessable out side the form or class.

Ken
-----------
"Brett" <no@spam.net> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
If I have many hard coded values such as file paths, file names, timeouts,
etc, where is the best place to define them? Meaning, in the case
something
needs changing for example, rather than running down all the subs or
functions that may contain these values, I'd like one place to change them
and have that changed reflected in the subs or functions that use those
values. I'd like to avoid globals; keeping the values private to only
those
subs or functions using them.

Thanks,
Brett

Nov 21 '05 #4

"Brett" <no@spam.net> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
If I have many hard coded values such as file paths, file names, timeouts,
etc, where is the best place to define them? Meaning, in the case something needs changing for example, rather than running down all the subs or
functions that may contain these values, I'd like one place to change them
and have that changed reflected in the subs or functions that use those
values. I'd like to avoid globals; keeping the values private to only those subs or functions using them.

Thanks,
Brett


In situations like this - what do you think of including the file paths,
file names, timeouts, and those hard-code values in a separate text file you
can read at run-time.
The program would not need to be modified when things change - just change
the values in the file.
Nov 21 '05 #5

"Hal Rosser" <hm******@bells outh.net> wrote in message
news:1D******** ******@bignews2 .bellsouth.net. ..

"Brett" <no@spam.net> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
If I have many hard coded values such as file paths, file names,
timeouts,
etc, where is the best place to define them? Meaning, in the case

something
needs changing for example, rather than running down all the subs or
functions that may contain these values, I'd like one place to change
them
and have that changed reflected in the subs or functions that use those
values. I'd like to avoid globals; keeping the values private to only

those
subs or functions using them.

Thanks,
Brett


In situations like this - what do you think of including the file paths,
file names, timeouts, and those hard-code values in a separate text file
you
can read at run-time.
The program would not need to be modified when things change - just change
the values in the file.


Is this how it is normally done?

This file would only need to be read the first time the program loads
correct? It will also only be for globals right?

Thanks,
Brett
Nov 21 '05 #6

"Brett" <no@spam.net> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..

"Hal Rosser" <hm******@bells outh.net> wrote in message
news:1D******** ******@bignews2 .bellsouth.net. ..

"Brett" <no@spam.net> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
If I have many hard coded values such as file paths, file names,
timeouts,
etc, where is the best place to define them? Meaning, in the case

something
needs changing for example, rather than running down all the subs or
functions that may contain these values, I'd like one place to change
them
and have that changed reflected in the subs or functions that use those
values. I'd like to avoid globals; keeping the values private to only

those
subs or functions using them.

Thanks,
Brett


In situations like this - what do you think of including the file paths,
file names, timeouts, and those hard-code values in a separate text file
you
can read at run-time.
The program would not need to be modified when things change - just change the values in the file.


Is this how it is normally done?

This file would only need to be read the first time the program loads
correct? It will also only be for globals right?

Thanks,
Brett

Can be used for anything that has to be hard-coded.
Some do something like this - for Sales Tax Rate and the like
- If the rate changes - someone can change the rate in the file - and no
re-programming is required for a change in rates.
A separate file for each piece of data is one way to do it -
frinstance a file named "stateTaxRate.d at" can have one entry like ".075".
When the state changes the rate - tell the user to change the file entry to
".085" - or whatever the new rate is.

Nov 21 '05 #7

"Hal Rosser" <hm******@bells outh.net> wrote in message
news:Uw******** *********@bigne ws6.bellsouth.n et...

"Brett" <no@spam.net> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..

"Hal Rosser" <hm******@bells outh.net> wrote in message
news:1D******** ******@bignews2 .bellsouth.net. ..
>
> "Brett" <no@spam.net> wrote in message
> news:%2******** ********@tk2msf tngp13.phx.gbl. ..
>> If I have many hard coded values such as file paths, file names,
>> timeouts,
>> etc, where is the best place to define them? Meaning, in the case
> something
>> needs changing for example, rather than running down all the subs or
>> functions that may contain these values, I'd like one place to change
>> them
>> and have that changed reflected in the subs or functions that use
>> those
>> values. I'd like to avoid globals; keeping the values private to only
> those
>> subs or functions using them.
>>
>> Thanks,
>> Brett
>>
>>
>
> In situations like this - what do you think of including the file
> paths,
> file names, timeouts, and those hard-code values in a separate text
> file
> you
> can read at run-time.
> The program would not need to be modified when things change - just change > the values in the file.


Is this how it is normally done?

This file would only need to be read the first time the program loads
correct? It will also only be for globals right?

Thanks,
Brett

Can be used for anything that has to be hard-coded.
Some do something like this - for Sales Tax Rate and the like
- If the rate changes - someone can change the rate in the file - and no
re-programming is required for a change in rates.
A separate file for each piece of data is one way to do it -
frinstance a file named "stateTaxRate.d at" can have one entry like ".075".
When the state changes the rate - tell the user to change the file entry
to
".085" - or whatever the new rate is.

I see. I suppose you could build that into the interface for the user to
make changes as well right?

Using the text files for many variables, will that be a bunch of parsing -
instr(), mid(), perhaps regular expressions and the like in other words?
They just don't seem like the most efficient method. I guess they could be
seperated by chr(13) & chr(10).

Would an XML file work better?

Thanks,
Brett
Nov 21 '05 #8
Options may be: XML Resource File, Small DataBase, Serialized Class, etc.

"Brett" wrote:

"Hal Rosser" <hm******@bells outh.net> wrote in message
news:Uw******** *********@bigne ws6.bellsouth.n et...

"Brett" <no@spam.net> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..

"Hal Rosser" <hm******@bells outh.net> wrote in message
news:1D******** ******@bignews2 .bellsouth.net. ..
>
> "Brett" <no@spam.net> wrote in message
> news:%2******** ********@tk2msf tngp13.phx.gbl. ..
>> If I have many hard coded values such as file paths, file names,
>> timeouts,
>> etc, where is the best place to define them? Meaning, in the case
> something
>> needs changing for example, rather than running down all the subs or
>> functions that may contain these values, I'd like one place to change
>> them
>> and have that changed reflected in the subs or functions that use
>> those
>> values. I'd like to avoid globals; keeping the values private to only
> those
>> subs or functions using them.
>>
>> Thanks,
>> Brett
>>
>>
>
> In situations like this - what do you think of including the file
> paths,
> file names, timeouts, and those hard-code values in a separate text
> file
> you
> can read at run-time.
> The program would not need to be modified when things change - just

change
> the values in the file.

Is this how it is normally done?

This file would only need to be read the first time the program loads
correct? It will also only be for globals right?

Thanks,
Brett

Can be used for anything that has to be hard-coded.
Some do something like this - for Sales Tax Rate and the like
- If the rate changes - someone can change the rate in the file - and no
re-programming is required for a change in rates.
A separate file for each piece of data is one way to do it -
frinstance a file named "stateTaxRate.d at" can have one entry like ".075".
When the state changes the rate - tell the user to change the file entry
to
".085" - or whatever the new rate is.

I see. I suppose you could build that into the interface for the user to
make changes as well right?

Using the text files for many variables, will that be a bunch of parsing -
instr(), mid(), perhaps regular expressions and the like in other words?
They just don't seem like the most efficient method. I guess they could be
seperated by chr(13) & chr(10).

Would an XML file work better?

Thanks,
Brett

Nov 21 '05 #9
I'm surprised no-one here has mentioned App.config yet (or did I miss it?)

Right click on your project in the solution explorer and choose to add a new
item. From the list of items that you can add to the project, scroll down
and find the one called ApplicationConf iguration File. Select it, call it
app.config and click Open to add it to the file.

In the file you just added, drop in an <appSettings> section and in that add
your values, like this
<?xml version="1.0" encoding="utf-8" ?>

<configuratio n>

<appSettings>

<add key="DirectoryN ame" value="c:\test"/>

</appSettings>

</configuration>

Here I've addded in a single entry called DirectoryName, with a value of
"c:\test"

Now, to get at that, and obviously the whole mass of other values you want
to store, just go ahead and create a class with some shared properties on
it, like this.

Imports System.Configur ation

Public Class AppSettings

Public Shared ReadOnly Property DirectoryName() As String

Get

Return ConfigurationSe ttings.AppSetti ngs("DirectoryN ame")

End Get

End Property

End Class

If I ever want to pull a value out of that app.settings file now I just call
AppSettings.wha teverpropertyyo ucoded up

Hope that helps,
--
Pete Wright
Author of ADO.NET Novice to Pro for Apress
www.petewright.org

"Brett" <no@spam.net> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
If I have many hard coded values such as file paths, file names, timeouts,
etc, where is the best place to define them? Meaning, in the case
something needs changing for example, rather than running down all the
subs or functions that may contain these values, I'd like one place to
change them and have that changed reflected in the subs or functions that
use those values. I'd like to avoid globals; keeping the values private
to only those subs or functions using them.

Thanks,
Brett

Nov 21 '05 #10

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

Similar topics

11
2018
by: GhislainTanguay | last post by:
Hi everyone, i work on a ASP (Not .NET but version 3) project. This project is on our server for development. I use SQL-SERVER, IIS and VB for DLL. On the server i have create a folder with my project name "Aptitudes" under inetpub/wwwroot/. I recently talked with an external consultant and he told me that I did something wrong when I created my Aptitudes folder. He said that when we will be ready for transfering the project on a...
97
27772
by: s | last post by:
Can I do this: #define MYSTRING "ABC" .. .. .. char mychar = MYSTRING; .. .. ..
1
1926
by: Rasika Wijayaratne | last post by:
Hello, Can I get feedback on these .NET coding best practices please. Thanks to Konrad Rudolph and Jon Skeet for the replies to my previous post on 'Writing Properties.' Thanks in advance to all replies to this post as well, as I am having probs posting from MS Communities site (posting from Google). =========== Avoid Returning null Instead of Array, String, or Collection
6
3626
by: Andrea Williams | last post by:
Where is the best place to put global variables. In traditional ASP I used to put all of them into an include file and include it in every page. Will the Global.aspx.cs do that same thing? Thanks in Advance! Andrea
8
1536
by: Charlie | last post by:
Hi: My ASP.NET app opens and closes database connection in several pages. Rather than hard coding string into every page, is there a place I can put it where all pages will be able to access it. In days of fat client programming, I put in INI file. Looking for similar solution. Thanks, Charlie
5
1733
by: Janaka | last post by:
I'm making a web application on my local server which will then be rolled out onto our live site. My problem is that i tend to have to comment out and make a few new hard-coded lines in my files to edit changes locally and then i have to reverse this process to make any changes live. See below // local myLink.NavigateUrl = "http://localhost/TestSite/Printout.aspx"; myLink.NavigateUrl = http://www.mysite.com/Printout.aspx; I'm thinking...
10
1977
by: Mike Logan | last post by:
I am using the "contract first" design methodology. Contract First is design the WSDL first then design the server and client. However I must design my XSD/XML Schema before anything. I am developing my schema now. I have a version on my schema. However once I start the server side code, how is the server now that the right "complexType" is being passed? What happens if this complexType my web service consumes needs to be...
9
1437
by: ward | last post by:
Good morning. I created an edit_task page that allows the user to edit tasks for the database. I entered some text and used some hard returns. Put when I went to view the tasks (using a PHP script if it matters), the hard returns didn't "take." None of em. All of the text is jumbled together. Well I checked within the MySQL database just now (before uploading
21
1643
by: John Salerno | last post by:
If I want to make a list of four items, e.g. L = , and then figure out if a certain element precedes another element, what would be the best way to do that? Looking at the built-in list functions, I thought I could do something like: if L.index('A') < L.index('D'): # do some stuff But I didn't know if maybe there was a preferred method for this type of
0
8425
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8326
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
8845
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8743
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
8522
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,...
1
6177
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
5647
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
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
4333
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.