1 Replies - 2116 Views - Last Post: 28 March 2013 - 02:36 PM Rate Topic: -----

#1 Oblivic909  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 28-March 13

Visual Basic Calorie Counter

Posted 28 March 2013 - 02:31 PM

My problem is that when I run my project and I put in a value the results come out in the Labels rather than in the text boxes. I don't need you to do my work just some help.

This is my assignment

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 calories:
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. to Print the Form.
and to Exit.
Make the form's Text property 'Calorie Counter.
Cock: Write the code for each button. Make sure to catch any bad input
data and display a message box to the user.

I do not need to have a print
[
'Program 3
'3/21/2013
'Jovanni D. Garcia
'This program calculates the calories of protein, fat, 
'and carbohydrates. then gives you the sum of the calories, total food items, and total calories

'This turns on option strict
Option Strict On

Public Class Form1
    Inherits System.Windows.Forms.Form

    'Declare constants
    Const intFatCal As Integer = 9I
    Const intProCal As Integer = 4I
    Const intCarbCal As Integer = 4I

    Private Sub btnCal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCal.Click
        'Calculates total calories, show total items, and accumalate calories

        Dim intFat As Integer
        Dim intPro As Integer
        Dim intCarb As Integer
        Dim TotalCal As Integer
        Static SumItems As Integer
        Static AccCal As Integer

        Try
            'convert values to numeric values

            intFat = CInt(txtFat.Text)
            intPro = CInt(txtPro.Text)
            intCarb = CInt(txtCarb.Text)
            'multiples the input and calories per carb, fat, protein. then gives you the sum of calories
            'and total items and total calories 
            TotalCal = (intFat * 9) + (intCarb * 4) + (intPro * 4)
            SumItems += 1
            AccCal += TotalCal




            txtTotalCal.Text = FormatNumber(TotalCal)
            txtTotalItems.Text = FormatNumber(SumItems)
            txtCal.Text = FormatNumber(TotalCal)


        Catch MyErrs As InvalidCastException
            MessageBox.Show("Numeric data only.", "Data Entry Error", _
            MessageBoxButtons.OK, MessageBoxIcon.Exclamation)


        Catch MyErrs As Exception

            MessageBox.Show("Error:" & MyErrs.Message)


        End Try
    End Sub

    Private Sub btnClr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClr.Click
        'Clear Text boxes
        txtPro.Clear()
        txtCarb.Clear()
        TotalCal.Text = ""
        SumItems.Text = ""
        AccCal.Text = ""

        With txtFat
            .Clear()
            .Focus()

        End With

    End Sub

    Private Sub btnExt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExt.Click
        'end program
        Me.Close()
    End Sub

   


End Class 
]

This post has been edited by modi123_1: 28 March 2013 - 02:35 PM
Reason for edit:: highlight the text and just click the 'code' button in the text editor


Is This A Good Question/Topic? 0
  • +

Replies To: Visual Basic Calorie Counter

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8390
  • View blog
  • Posts: 31,200
  • Joined: 12-June 08

Re: Visual Basic Calorie Counter

Posted 28 March 2013 - 02:36 PM

Quote

My problem is that when I run my project and I put in a value the results come out in the Labels rather than in the text boxes.

.. and you are sure your labels do not have names that look like textboxes and vise-versa?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1