Users enter numbers into textboxes, and the values are displayed on a graph. I want to be sure users type numbers in the textboxes, so I tried:
double xValue;
double yValue;
Double.TryParse(xTextBox.Text, out xValue);
Double.TryParse(yTextBox.Text, out yValue);
chart1.Series["data1"].Points.AddXY(xValue, yValue);
Double.TryParse()
validates whether users type numbers, but I'm not sure how to code for when users don't type numbers. Double.TryParse()
will assign xValue
or yValue
a 0--but I also want users to be able to enter 0 values so I cannot just code something like
if (xValue!=0 && yValue!=0)...
Something like
if (xTextBox.Text!="0") {
Double.TryParse(xTextBox.Text, out xValue);
}
seems like awkward code that will just get more. What's the standard way to make sure users entered a double?