K7SN
January 3rd, 2006, 07:56 PM
Howdy
I hate using things I don't understand. I wanted a simple boolean function test if a string could be parsed. While I can validate it using the typical Regex("[^.0-9]") I wanted something more helpful for all instances and I need to validate a range. Double.TryParse was just the ticket BUT it has this argument I have no clue what its use is for in my simple situation and wondered what the use is I don't understand. My solution works as I want it to but my variable Huh bothers me. Any advice?
private void btnOK_Click(object sender, System.EventArgs e)
{
bool isError = false;
double val;
System.IFormatProvider Huh = null;
if ( txtBoxConfidenceLevel.Text == "")
{
errorProvider1.SetError(txtBoxConfidenceLevel, "Enter a confidence level");
isError = true;
}
else errorProvider1.SetError(txtBoxConfidenceLevel, "");
if (Double.TryParse(txtBoxConfidenceLevel.Text, System.Globalization.NumberStyles.Float, Huh, out val))
{
if (val <= 0.5)
{
errorProvider1.SetError(txtBoxConfidenceLevel, "Confidence level must be greater than 0.50");
isError = true;
}
if (val >= 1.0)
{
errorProvider1.SetError(txtBoxConfidenceLevel, "Confidence level must be less than 1.00");
isError = true;
}
}
else {
errorProvider1.SetError(txtBoxConfidenceLevel, "Unable to parse entry as a double value");
isError = true;
}
if (!isError)
{
UpdateUserSelection();
this.Close();
}
}
I hate using things I don't understand. I wanted a simple boolean function test if a string could be parsed. While I can validate it using the typical Regex("[^.0-9]") I wanted something more helpful for all instances and I need to validate a range. Double.TryParse was just the ticket BUT it has this argument I have no clue what its use is for in my simple situation and wondered what the use is I don't understand. My solution works as I want it to but my variable Huh bothers me. Any advice?
private void btnOK_Click(object sender, System.EventArgs e)
{
bool isError = false;
double val;
System.IFormatProvider Huh = null;
if ( txtBoxConfidenceLevel.Text == "")
{
errorProvider1.SetError(txtBoxConfidenceLevel, "Enter a confidence level");
isError = true;
}
else errorProvider1.SetError(txtBoxConfidenceLevel, "");
if (Double.TryParse(txtBoxConfidenceLevel.Text, System.Globalization.NumberStyles.Float, Huh, out val))
{
if (val <= 0.5)
{
errorProvider1.SetError(txtBoxConfidenceLevel, "Confidence level must be greater than 0.50");
isError = true;
}
if (val >= 1.0)
{
errorProvider1.SetError(txtBoxConfidenceLevel, "Confidence level must be less than 1.00");
isError = true;
}
}
else {
errorProvider1.SetError(txtBoxConfidenceLevel, "Unable to parse entry as a double value");
isError = true;
}
if (!isError)
{
UpdateUserSelection();
this.Close();
}
}