Solved

Loading values from the Settings.Settings-file incorrect.

Posted on 2012-04-01
6
245 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

705 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now