You have introduced a Globalization / Regional problem by requiring the default value to be a string
.
double? value = InputBox.GetDouble("xyz", "1.0");
double? value2 = InputBox.GetDouble("xyz", "1,0");
One of these two will fail, but not on every machine or country or even on the the same line. The 'ToString()
', 'Parse()
', and 'string.Format()
' methods are running under the regional settings of the thread. Which is by default the same as the RegionalSettings
for the logged on user, but it does not have to be. For more information, read the helpfile for these functions.
We can elevate the pain for the default value by making the default value the same type as the result; this helps greatly, unless string
is the native value for the default, in which case you might need two versions of the method.
Simple fix:
public static double? GetDouble(string caption, double?defaultValue)
{
ClearLastError();
using (InputForm inForm = new InputForm(caption, defaultValue.ToString()))
{
[edit: and the rest]
}
}
Doing that 'computer thing' ever since the C64.
Sometimes I feel that being a programmer is much like being a doctor: You just have to know everything and if you don't, something dies.
Either being an application or a patient.
Oddly enough, more people care about the death of their application, than the massacre of people...