473,395 Members | 1,471 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

shared variables or messages in C#

Hi group,

Back to my C and Pascal programming under windows we used to have a
segment or external file to keep common messages (error, warning and ...)!
now what?
how can I have my messages (associated with a project) in a unit or file ?
then I would be able to modifiy just a file instead of the whole messages in
project files ?

thanks in advance
Nov 15 '05 #1
9 2980
You can do the same by having a class that holds all static variables to the messages, errors, etc

public class MessageHolde

public static int Message1 = 10
public static string ErrorMessageXYZ = "Test"
..
Tu-Thac

----- Ramsin Savra wrote: ----

Hi group

Back to my C and Pascal programming under windows we used to have
segment or external file to keep common messages (error, warning and ...)
now what
how can I have my messages (associated with a project) in a unit or file
then I would be able to modifiy just a file instead of the whole messages i
project files

thanks in advanc

Nov 15 '05 #2
You can do the same by having a class that holds all static variables to the messages, errors, etc

public class MessageHolde

public static int Message1 = 10
public static string ErrorMessageXYZ = "Test"
..
Tu-Thac

----- Ramsin Savra wrote: ----

Hi group

Back to my C and Pascal programming under windows we used to have
segment or external file to keep common messages (error, warning and ...)
now what
how can I have my messages (associated with a project) in a unit or file
then I would be able to modifiy just a file instead of the whole messages i
project files

thanks in advanc

Nov 15 '05 #3
Thanks for your help.


"Tu-Thach" <an*******@discussions.microsoft.com> wrote in message
news:FE**********************************@microsof t.com...
You can do the same by having a class that holds all static variables to the messages, errors, etc.
public class MessageHolder
{
public static int Message1 = 10;
public static string ErrorMessageXYZ = "Test";
...
}

Tu-Thach

----- Ramsin Savra wrote: -----

Hi group,

Back to my C and Pascal programming under windows we used to have a segment or external file to keep common messages (error, warning and ....)! now what?
how can I have my messages (associated with a project) in a unit or file ? then I would be able to modifiy just a file instead of the whole messages in project files ?

thanks in advance

Nov 15 '05 #4
Thanks for your help.


"Tu-Thach" <an*******@discussions.microsoft.com> wrote in message
news:FE**********************************@microsof t.com...
You can do the same by having a class that holds all static variables to the messages, errors, etc.
public class MessageHolder
{
public static int Message1 = 10;
public static string ErrorMessageXYZ = "Test";
...
}

Tu-Thach

----- Ramsin Savra wrote: -----

Hi group,

Back to my C and Pascal programming under windows we used to have a segment or external file to keep common messages (error, warning and ....)! now what?
how can I have my messages (associated with a project) in a unit or file ? then I would be able to modifiy just a file instead of the whole messages in project files ?

thanks in advance

Nov 15 '05 #5
"Ramsin Savra" <rs****@otxresearch.com> wrote:
Hi group,

Back to my C and Pascal programming under windows we used to have a
segment or external file to keep common messages (error, warning and ...)!
now what?
how can I have my messages (associated with a project) in a unit or file ?
then I would be able to modifiy just a file instead of the whole messages in
project files ?

thanks in advance


You could create a class whose sole purpose is to hold the messages.

e.g.:

// Messages.cs

namespace MyApp
{

class ErrorMessages
{
public const string SomeError = "Some error has occured.";
//...
}

}

Here we have created a constant *static* string object (constant
members are automatically static in C#).

Now you can use it like this:

namespace MyApp
{

class MainForm
{
public void Foo()
{
if (anErrorOccured) {
MessageBox.Show(ErrorMessages.SomeError);
}
}
}

}

HTH
Nov 15 '05 #6
"Ramsin Savra" <rs****@otxresearch.com> wrote:
Hi group,

Back to my C and Pascal programming under windows we used to have a
segment or external file to keep common messages (error, warning and ...)!
now what?
how can I have my messages (associated with a project) in a unit or file ?
then I would be able to modifiy just a file instead of the whole messages in
project files ?

thanks in advance


You could create a class whose sole purpose is to hold the messages.

e.g.:

// Messages.cs

namespace MyApp
{

class ErrorMessages
{
public const string SomeError = "Some error has occured.";
//...
}

}

Here we have created a constant *static* string object (constant
members are automatically static in C#).

Now you can use it like this:

namespace MyApp
{

class MainForm
{
public void Foo()
{
if (anErrorOccured) {
MessageBox.Show(ErrorMessages.SomeError);
}
}
}

}

HTH
Nov 15 '05 #7
C# Learner <cs****@learner.here> wrote:

The name wasn't so good...
class ErrorMessages
{
public const string General = "Some error has occured.";
}
MessageBox.Show(ErrorMessages.General);


That's better.
Nov 15 '05 #8
C# Learner <cs****@learner.here> wrote:

The name wasn't so good...
class ErrorMessages
{
public const string General = "Some error has occured.";
}
MessageBox.Show(ErrorMessages.General);


That's better.
Nov 15 '05 #9
In addition to the other replies, you may want to consider writing a class
to load messages from a stream or the resources class and use resources or
an xml or name=value style file you parse yourself to hold your error
messages. It will definatly come in handy if you intend to localize your
code(just modify the file, no code changes). Infact researching localization
will probably turn up the best techniques to use anyway, even if you don't
intend to localize.
"Ramsin Savra" <rs****@otxresearch.com> wrote in message
news:eE**************@TK2MSFTNGP11.phx.gbl...
Hi group,

Back to my C and Pascal programming under windows we used to have a
segment or external file to keep common messages (error, warning and ...)!
now what?
how can I have my messages (associated with a project) in a unit or file ?
then I would be able to modifiy just a file instead of the whole messages in project files ?

thanks in advance

Nov 15 '05 #10

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

Similar topics

3
by: tom | last post by:
Hello, I'm using the ms data access application blocks. My question is about the fact that everywhere shared methods are used. Does this mean that when more than 1 user at the same time...
0
by: Ramsin Savra | last post by:
Hi group, Back to my C and Pascal programming under windows we used to have a segment or external file to keep common messages (error, warning and ...)! now what? how can I have my messages...
4
by: John Kraft | last post by:
Hi all, My question is more of a phylisophical one here, but I am wondering what the difference is (effectively and performance wise) between using a shared variable/static variable and using a...
15
by: Rob Nicholson | last post by:
A consequence of the ASP.NET architecture on IIS has just hit home with a big thud. It's to do with shared variables. Consider a module like this: Public Module Functions Public GlobalName As...
9
by: Bob Day | last post by:
VS 2003, vb.net , sql msde... I have an application with multiple threads running. Its a telephony application where each thread represents a telephone line. For code that would be the same...
8
by: gemel | last post by:
I have been reading sime material in .NET that throws some doubt on my understanding of shared procedures. With regard to object programming I assumed that variables declared within a class were...
2
Semprini
by: Semprini | last post by:
Hiya, I'm programming a dll in VC6 which is uses windows hooks (WH_GETMESSAGE). So I have a HOOKPROC which is called whenever messages are sent the the monitored hwnd I have a shared data...
3
by: ragi | last post by:
Hi Friends, Could you please tell me about, 1. What a shared library in c contains 2. (.a) file extension for shared libraries. 3. Is shared libraries are reentrant. Thanking you in...
0
by: netkadirisani | last post by:
Hi, i built a dll (used vb.net) that has some shared variables. the basic idea of using the shared variables is to read some values from the database and save them in the shared variables during the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...

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.