Format Exception in Windows Form Help?
Okay, I've got an order form that needs to calculate the total each time a quantity is updated. I have it set up the way I think it should work. I've added one of my methods here for my QuantityBox_TextChanged. I have 3 quantity boxes like this, and I set them all up like this pretty much. When I select a check box, it enables the quantity box - but when I type a number in it, it throws an exception. Any ideas?
private void WhiteFuzzyDiceQuantityBox_TextChanged(object sender, EventArgs e)
{
double result = 0.0;
// exception handling for quantity boxes(no text allowed in them)
try
{
double RedQuantityBox = double.Parse(this.RedFuzzyDiceQuantityBox.Text);
double BlackQuantityBox = double.Parse(this.BlackFuzzyDiceQuantityBox.Text);
double WhiteQuantityBox = double.Parse(this.WhiteFuzzyDiceQuantityBox.Text);
result = (BlackQuantityBox + WhiteQuantityBox + RedQuantityBox)*cost;
}
catch(FormatException)
{
MessageBox.Show("Not a valid number for quantity box, \nplease enter a number");
}
//displays results
this.DisplayResults(result);
}
Related Article: windows form application shutdown mode
is a C# discussion thread by Z33shan that has 2 replies, was last updated 9 months ago and has been tagged with the keywords: windows, form, applications, c#, visual, studio, 2010.
kiail
Light Poster
40 posts since Feb 2012
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0
Oh yeah, it only throws it once, after i put a number in after it throws it, it does what it is supposed to do.
kiail
Light Poster
40 posts since Feb 2012
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0
Question Self-Answered as of 1 Year Ago
I figured it out using something else.
kiail
Light Poster
40 posts since Feb 2012
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0