Convert Text to Single -- Convert.ToSingle -- Input string was not in a correct format
Posted on 2006-11-09
I have a textbox "MyBox" that users input text into. In this case, it is numeric (for which I can ignore non-numeric input, but that's not the question). I do something like this:
MyValue = Convert.ToSingle(MyBox.Text)
However, if the text is empty or alphabetic (e.g., "Hello, world."), I get an error "Input string was not in a correct format." Of course, I can pre-test for that, but I was wondering if there was some easy step that I was overlooking, like one that change non-numeric values to zero instead.