Solved

Loading values from the Settings.Settings-file incorrect.

Posted on 2012-04-01
6
250 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 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

738 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