Calculations for lbs. and ozs.

Sharad

Registered User.
Local time
Today, 03:00
Joined
Jan 23, 2003
Messages
26
I have a Form where these calculations are done for additive to be added to the product. User enters the name, weight of the product and at the Click of the Calculate Button calculations are done. I have been using the following code:

Dim lbs As Double
Dim ozs As Integer

lbs = Val(txtOilWeight.Value) * (Val(lstPercentage1.ItemData(0)) / 100)
ozs = (lbs - Int(lbs)) * 16
amount = (Int(lbs) & " lbs " & ozs & " ozs")

End If

txtAdditive1Amount.Value = amount

End Sub

This code works fine. However, if I Enter weight 45950 lbs. and the additive is 8 oz. per 1000 lbs it displays 22 lbs. and 16 ozs. and not 23 lbs. Why ?

To make this clear, Type, Weight of the additive are all being derived from a table. These calculated weights are not saved in the Table but are displayed in the txtBox.

I am at a loss to understand this. Any HELP will be appreciated

Thanks
:confused:
 
Try this:

Code:
Dim lbs As Integer
Dim ozs As Integer
Dim parts As Double

'Get the parts needed
parts = Val(txtOilWeight.Value) * (Val(lstPercentage1.ItemData(0)) / 100)

'Use the Integer Divide to get the lbs
lbs = parts \ 16

'Use the Mod (Remainder) of the parts divided by 16
ozs = parts Mod 16 '(lbs - Int(lbs)) * 16

'Put the string together
amount = lbs & " lbs " & ozs & " ozs"


txtAdditive1Amount.Value = amount
 

Users who are viewing this thread

Back
Top Bottom