Consider the scenario where the input value must be valid.
public static double? GetDouble(string caption, string defaultValue, bool mustBeValid = false)
{
ClearLastError();
using (InputForm inForm = new InputForm(caption, defaultValue))
{
while (true)
{
if (inForm.ShowDialog() != DialogResult.Cancel)
{
if (inForm.StringValue != string.Empty)
{
try
{
return double.Parse(inForm.StringValue);
}
catch (Exception ex)
{
LastError = ex;
}
}
}
if(mustBeValid)
{
MessageBox.Show("You must enter a valid value");
} else
{
return null;
}
}
}
}
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...