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
It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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