Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Loading values from the Settings.Settings-file incorrect.

Posted on 2012-04-01
6
Medium Priority
?
254 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
[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
  • 3
  • 2
6 Comments
 
LVL 86

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 86

Accepted Solution

by:
Mike Tomlinson earned 2000 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
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 86

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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 …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

610 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