|
Home > Archive > MCSD > June 2002 > Calculate percent of Calories from Fat
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Calculate percent of Calories from Fat
|
|
| ngo_28 2002-06-06, 2:26 pm |
| Hello guys. I am a newbie to VB 6.0.
Please help....here is the question.
Caculate the percentage of calories from fat, this percentage can be caculated by multiplying the number of grams of fat in one serving by 9, dividing that number by the total number of calories per serving and multiplying the result by 100. Write a prgram that requests the name, number of calories per serving, and the grams of fat per serving as inputs(textBoxes). I'm using low fat milk as example:
Name of food =low fat milk
calories per serving=120
grams of fat per serving =5
below is what I coded so far...i don't know id I am doing this right.
Private Sub cmdButton_Click()
Dim x As Integer, y As Integer, num As Integer, calories As Integer, fat As Integer
x = 9
y = 100
num = Val(txtcalories.Text)
num = Val(txtfat.txt)
Thnk you, | |
| TW2001 2002-06-07, 1:19 am |
| What exactly are you asking? You dont have much there and your only looking at a simple formula. Take your inputs,assign them to your variables,assign your formulas to a var compute it and output it back to the form or Msg box. | |
| 2lazybutsmart 2002-06-08, 7:49 am |
| ur question is so simple. you'll get to ask harder question later in your progress. here is the crank of code.
Code:-----------------------------
Private Function Calculate(snGramsOfFat As Single, snTotalCalories)
Dim snTempCalc as Single
snTempCalc = snGramsOfFat * 9
snTempCalc = snTempCalc / snTotalCalories
snTempCalc = snTempCalc * 100
Calculate = snTempCalc
End Function
-----------------------------------------
Place this small piece of code in the command buttion:------------------------
MsgBox "The Total percent of calories from fat for product: " & txtProductName & " is: " & Calculate(Val(txtGramsOfFatPer
Serving),Val(txtTotalCaloriesP
erServing))
Note: please change the names of the text boxes from the code or from the interface. all object name have to match. | |
| ngo_28 2002-06-14, 11:49 am |
| Thank you for the help with that problem....
well, I seem to be having a hard time studying VB 6.0. here is the problem i have run into...
Write a program to display a company’s payroll report in a picture box. The program
should read each employee’s name, hourly rate, and hours worked from a file and produce a report. Using the call statement and loops.
Employees should be paid time-and-a-half for hours in excess of 40.
Payroll Report for a Week
Employee HourlyRate HoursWorked GrossPay
Al Adams $6.50 38 $247.00
Bob Brown $5.70 50 $313.50
FinalTotal $550.50
your help is very much appreciated, thanks | |
| RichardJW 2002-06-24, 8:00 pm |
| Man...I hate to say this but you seem to know precious little about programming. It's absolutely and completely pathetic that you can't work this out for yourself. In fact it is tragic !!! Learn this stuff !!! Put your head down and get to it. I know this sounds patronising but I'm not going to apologize for it. If you've got a brain then use it. If you don't then too bad - admit defeat. | |
| ngo_28 2002-06-25, 11:10 pm |
| Problem resolved already...look at the date....long time ago.... | |
| RichardJW 2002-06-26, 5:18 am |
| Actually what I said there was probably too harsh so I apologize for that in this case. |
|
|
|
|