Solved

Loading values from the Settings.Settings-file incorrect.

Posted on 2012-04-01
6
248 Views
Last Modified: 2012-06-27
Dear Experts,

I have 4 variables declared in the Settings.Settings-file:

Name = MinVal, Type = string, Value = 3.9
Name = MinRng, Type = string,  Value = 4.4
Name = MaxRng, Type = string, Value = 6.7
Name = MaxVal, Type = string, Value = 8.3

And this I have in the loadevent of my dialog-form called Settings:

        private void Settings_Load(object sender, EventArgs e)
        {
            this.spdMinVal.Text = Properties.Settings.Default.MinVal;
            this.spdMinRng.Text = Properties.Settings.Default.MinRng;
            this.spdMaxRng.Text = Properties.Settings.Default.MaxRng;
            this.spdMaxVal.Text = Properties.Settings.Default.MaxVal;
        }

Open in new window


But in my 4 spinedit-components from DevExpress I get these
values:

39,0 - 44,0 - 67,0 - 83,0

instead of:

3,9 - 4,4 - 6,7 - 8,3

How can I solve this?

Who knows the answer and is willing to help me?

Greetings,

Peter Kiers
0
Comment
Question by:peterkiers
  • 3
  • 2
6 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 37794001
Does that control have a Value() property instead of a Text() one?
0
 
LVL 1

Author Comment

by:peterkiers
ID: 37794916
Hi,

When I change the default values to "3,9", "4,4" etc.. computers in the US doesn't recognize this. Because you use a period instead of a comma.
so I get: "39.0", "44.0" etc.. And ofcaurse visa versa. When I change the default values to "3.9", "4.4" etc.. I get "39,0", "44,0". Because we use
a comma instead of a period. So what I want to try is to set the default values with a period. But when the form is loaded the code has to check
the currentculure and convert it. I have this line of code from my previous question:

private System.Globalization.CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentCulture;

Is it posible in this load-event the code read the default-values and the checks the current culture and convert the value
and display it then in the spinedit-components.

        private void Settings_Load(object sender, EventArgs e)
        {
            this.spdMinVal.EditValue = Properties.Settings.Default.MinVal;
            this.spdMinRng.EditValue = Properties.Settings.Default.MinRng;
            this.spdMaxRng.EditValue = Properties.Settings.Default.MaxRng;
            this.spdMaxVal.EditValue = Properties.Settings.Default.MaxVal;
        }

Greetings,

Peter Kiers
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 37796081
I would pick a culture and then hard code that into your Load() event with a Parse() call.  Then you can use ToString() and it will be converted to the current culture.  Something like:
        private void Settings_Load(object sender, EventArgs e)
        {
            Decimal MinVal;
            Decimal MinRng;
            Decimal MaxVal;
            Decimal MaxRng;
            CultureInfo ci = new CultureInfo("en-GB");

            if (Decimal.TryParse(Properties.Settings.Default.MinVal, NumberStyles.Any, ci, out MinVal)) // use Great Britain culture since that is hard-coded in settings
            {
                this.spdMinVal.EditValue = MinVal.ToString(); // <-- uses the current culture
            }
            if (Decimal.TryParse(Properties.Settings.Default.MinRng, NumberStyles.Any, ci, out MinRng)) // use Great Britain culture since that is hard-coded in settings
            {
                this.spdMinRng.EditValue = MinRng.ToString(); // <-- uses the current culture
            }
            if (Decimal.TryParse(Properties.Settings.Default.MaxVal, NumberStyles.Any, ci, out MaxVal)) // use Great Britain culture since that is hard-coded in settings
            {
                this.spdMaxVal.EditValue = MaxVal.ToString(); // <-- uses the current culture
            }
            if (Decimal.TryParse(Properties.Settings.Default.MaxRng, NumberStyles.Any, ci, out MaxRng)) // use Great Britain culture since that is hard-coded in settings
            {
                this.spdMaxVal.EditValue = MinVal.ToString(); // <-- uses the current culture
            }

Open in new window

0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 37796089
Oops...Line #23 should be:

                this.spdMaxRng.EditValue = MaxRng.ToString(); // <-- uses the current culture
0
 
LVL 1

Author Comment

by:peterkiers
ID: 37796272
Thanks Idle_Mind.

Peter
0
 
LVL 40
ID: 37799560
Why do you define your settings as strings when they are numbers? You will end up with the same kind of problems that you would get by defining a numeric field as text in a database.

If you define your settings as numerical values and apply ToString to them, they will automatically convert to the proper format for the environment in which they run.

Name = MinVal, Type = string, Value = 3.9
this.spdMinVal.Text = Properties.Settings.Default.MinVal.ToString()
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

860 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