Solved

Loading values from the Settings.Settings-file incorrect.

Posted on 2012-04-01
6
246 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual Studio editor? 1 38
I need help assigning an image to an image control in my VB.Net WPF project 3 44
Resolve Dependency Issues 4 47
Variable Event ? 3 23
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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…
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, f…

867 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

22 Experts available now in Live!

Get 1:1 Help Now