|
-
October 24th, 2011, 09:44 AM
#1
If Statement w/Message Box
I'm trying to get the message box to show if the two text boxes are left blank or their value is less than 0, I can't seem to get the message box to show up and even with a negative number it calculates any way instead of the message showing up. W/o any info (left blank) the program freezes =/
//declare variables
double dblFat;
double dblCarbs;
double dblFatCalories;
double dblCarbCalories;
double dblTotalCalories;
//assign values
dblFat = Double.Parse(txtFat.Text);
dblCarbs = Double.Parse(txtCarb.Text);
//Calculate Amount of Fat/Carb calories
dblFatCalories = dblFat * 9;
dblCarbCalories = dblCarbs * 4;
dblTotalCalories = dblFatCalories + dblCarbCalories;
//Assign results to label
txtFat.Text = Convert.ToString(dblFat);
txtCarb.Text = Convert.ToString(dblCarbs);
lblCarbCaloriesValue.Text = Convert.ToString(dblCarbCalories);
lblFatCaloriesValue.Text = Convert.ToString(dblFatCalories);
if (lblFatCaloriesValue.Text == "" || ((lblCarbCaloriesValue.Text == "") || (dblTotalCalories <= 0)))
{
MessageBox.Show("Please enter a valid number", "Missing Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|