Now, i have 3 text box
Fat , Protein , Carbohydrate
I have one label and 1 calculate button to calculate the total calories

How do i change the following code to perform such task?
i) Add total sum of calories from Fat / protein / carbohydrate (No need enter all 3 value)
ii) Create Error message on messagebox when value in textbox is character ( currently can't calculate because got error* )

iii) How can i create "Total Entered item" code on button to display on label? I have no idea on this code
BELOW IS MY VB.NET SOURCE CODE
Private Sub btnCalories_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalories.Click
Dim CaloriesResult As String
CaloriesResult = (txtFat.Text * 9) + (txtProtein.Text * 4) + (txtCarbo.Text * 4)
If txtFat.Text = "" And txtProtein.Text = "" And txtCarbo.Text = "" Then
MessageBox.Show("Please Enter Data")
ElseIf txtFat.Text = "" Then
MessageBox.Show("Please input your fat in gram.")
ElseIf txtProtein.Text = "" Then
MessageBox.Show("Please input your protein in gram.")
ElseIf txtCarbo.Text = "" Then
MessageBox.Show("Please input your carbohydrate in gram.")
Else
lblCaloriesDisplay.Text = CaloriesResult & " Calories"
End If
End Sub
This post has been edited by calsonstyle: 22 February 2009 - 12:00 PM

New Topic/Question
Reply



MultiQuote





|