Keeping a Running Total

Mwagner5600

Member
Joined
Mar 6, 2004
Messages
5
I have a programm where I need to keep a running total of the quantity and the total. I will paste the code I have so far.


_________________________________________________
Option Strict On

Public Class frmCalorieCounter
Inherits System.Windows.Forms.Form

" Windows Form Designer generated code "


Const mintFAT As Integer = 9
Const mintCARBS_PROTIEN As Integer = 4
Dim mintQuantity As Integer
Dim mintTotalCalories As Integer

Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Calculates the amount of Calories

Try
Dim intFat As Integer
Dim intCarbs As Integer
Dim intProtien As Integer
Dim intQuantity As Integer
Dim intTotalCalories As Integer
Dim intCalories As Integer

Convert inputValues to numeric variables
intFat = CInt(txtFat.Text)
intCarbs = CInt(txtCarbs.Text)
intProtien = CInt(txtProtien.Text)

Calculate Values
intCalories = intFat * mintFAT + intCarbs * mintCARBS_PROTIEN + intProtien * mintCARBS_PROTIEN
intQuantity = intFat + intCarbs + intProtien
intTotalCalories = intCalories

Format and Display answers
lblCalories.Text = FormatNumber(intCalories, 0)
lblQuantity.Text = FormatNumber(mintQuantity, 0)
lblTotalCalories.Text = FormatNumber(mintTotalCalories, 0)



Catch MyErr As Exception
MsgBox("Try to re-enter your data", MsgBoxStyle.Exclamation, "Data Error")
End Try


End Sub

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Closes the Programm

Me.Close()
End Sub

Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
Clears Proporties

lblCalories.Text = ""
txtProtien.Clear()
txtCarbs.Clear()
With txtFat
.Clear()
.Focus()
End With

End Sub
End Class

__________________________________________________________

I will attatch what my form looks like


I need to keep a running total of the mintquantity and mintTotalCalories
Sorry this is a little basic for all of you but im new to this programm and needed a little help.thanks
Mark


Edit-Sorry it is the summary part that needs to be the running total that i cant figure out
 

Attachments

Last edited by a moderator:
if you want to keep a running total you need to use += on your labels when adding the new values , eg:
Code:
[COLOR=Green]/// += will cause the count to increase ( adding your new value to the existing one )[/COLOR]
lblQuantity.Text += FormatNumber(mintQuantity, 0)
lblTotalCalories.Text += FormatNumber(mintTotalCalories, 0)
 
Do this:
Code:
labelname.Text = (Convert.ToInt32(labelname.Text) + numbertoadd).ToString()
First you have to convert the text to an integer (or any number data type you want to use) to add it with another number. Since that results in a number, you have to then convert the result to a string.
 
i already converted it to an integer when i formatted it. but what i was saying/typing was I needed to add up the 2 integers in my lable instad of just put 33 add 3+3 and get 6
 
hmm well its not exactly working for me. when im debugging the programm and type in 1 for fat 1 for carbs and 1 for protien it says 17 calores and 3 items (quantity) but then if i clear, and do it again it will say the same thing except 1717 calories and 33 items.
 
Back
Top