Food Project

  • From: "Marvin Hunkin" <startrekcafe@xxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Mon, 13 Oct 2008 21:16:07 +1100

Hi.
well, doing a project and will copy the project description below, and then 
discuss my question and problem, with a little bit of my code problem.

here's the project description:

3.1 Create a project that calculates the total of fat, carbohydrate, and 
protein
calories. Allow the user to enter (in text boxes) the grams of fat, the 
grams
of carbohydrates, and the grams of protein. Each gram of fat is nine calo-
ries; a gram of protein or carbohydrate is four calories.
Display the total calories for the current food item in a text box. Use
two other text boxes to display an accumulated sum of the calories and a
count of the items entered.
Form: The form should have three text boxes for the user to enter the
grams for each category. Include labels next to each text box indicating
what the user is to enter.
Include buttons to Calculate, to Clear the text boxes, and to Exit.
Make the form's Text property "Calorie Counter".
Code: Write the code for each button. Make sure to catch any bad input
data and display a message box to the user.


my question is:


how do i fix the vallidation for is numeric.

you enter the grams of fat, cars and rpteinprotein.
then you click calculate and it shows you the total calories, the 
accumulated amount of calories and the number of items entered.
now, got a is numeric test for fat, carbs and protein.
but it gives me a error, and traps the protein is numeric function.
so how do i fix it, so it does not pop up the message, when i input valid 
data?

so here's the code segment.

        If IsNumeric(tbGramsOfFatTextBox.Text) Then
            intGramsOfFatEnteredInteger = CInt(tbGramsOfFatTextBox.Text)
        else
                   MessageBox.Show("You Did Not Enter Grams Of Fat.", "Data 
Error", _
                            MessageBoxButtons.OK, 
MessageBoxIcon.Exclamation)
            tbGramsOfFatTextBox.Focus()
            Return

        End If

if IsNumeric(tbGramsOfCarbohydratesTextBox.Text) Then
            intGramsOfCarbsEnteredInteger = 
CInt(tbGramsOfCarbohydratesTextBox.Text)
else
messageBox.Show("You Did Not Enter Grams Of Carbohydrates.", "Data Error", _
messageBoxButtons.Ok, messageBoxIcon.Exclamation)
            tbGramsOfCarbohydratesTextBox.Focus()
return


        End If

         ' If IsNumeric(tbGramsOfProteinTextBox.Text) Then
        intGramsOfProteinEnteredInteger = CInt(tbGramsOfProteinTextBox.Text)
                             ' MessageBox.Show("You Did Not Enter Grams Of 
Protein.", "Data Error", _
                             'MessageBoxButtons.OK, 
MessageBoxIcon.Exclamation)
             ' tbGramsOfProteinTextBox.Focus()
             ' Return

         ' End If

and had to comment it out, so it would not keep falling over.
sorry for the long explanation, but had to explain myself, so you could 
understand the problem.
cheers Marvin.


__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: