BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi Chris and everybody,

I created a Custom Task for EG4.1 that must be bilingual, that is:
1. must work in English if the user set Tools/Options/General/English(United States)
2. must work in French if the user set Tools/Options/General/French(France)

In my task I need to validate user input numbers, entered as strings in textboxes for example “4.25”.
In my VB.NET code, I use the Convert.ToDouble(Me.TextBox1.Text) statement to convert the user’s entry in order to check the value (in the example, Me.TextBox1.Text = “4.25”).

As far as the EG4.1 language settings is Tools/Options/General/English(United States), the string “4.25” is converted to the double 4.25, which is great.

However, when the language settings is Tools/Options/General/French(France), “4.25” CAN NOT be converted to a double, as an exception is raised: “Input string was not in a correct format”. At the same time, “4,25” IS converted to a double, written 4,25 (which I don’t like because I write numerics is my SAS code using a period. And even if I replace the comma by the period when writing to my SAS code, I will have to do the reverse when I populate the form with the task state saved in XMLState. This is laborious!).

So in my CUSTOM TASKS, English(United States) seems to use the period as decimal separator, while French(France) uses the comma.

BUT in NATIVE EG4.1 tasks (those supplied by SAS), the period is used as decimal separator, regardless of the languages settings (English(United States) or French(France)).

So my question is: How do I force my Custom Task to have the same behaviour as the native task? (that is to recognise only the period as the decimal separator regardless of the EG4.1 languages settings).

Thanks for any help!

Maurice2
2 REPLIES 2
Bill_SAS
SAS Employee
You will need to add a second item to the Convert.ToDouble() statement. After your Me.TextBox1.Text add a second argument of "System.Globalization.CultureInfo.InvariantCulture". This will force the Convert.ToDouble() to use the default/US-english locale for the conversion no matter what Tools/Options/General/Locale settings.
ChrisHemedinger
Community Manager
Maurice,

You need to convert your numbers to strings using the InvariantCulture format provider. For example:

double myDouble = 4.25;
string value = myDouble.ToString(System.Globalization.CultureInfo.InvariantCulture);

That will prevent the French culture settings from influencing the text value.

Chris
SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1385 views
  • 0 likes
  • 3 in conversation