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).
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.