Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Have a logic Error Unable to do Math

Status
Not open for further replies.

starkid

Technical User
Feb 16, 2009
1
US
Basically my program is supposed to show hours worked, minutes leftover and weekly pay after a user enters total minutes worked and hourly pay rate into the text boxes.

I am able to get it so that in my labels it shows hours worked with another label that shows left over minutes using the division operator "\" for hours worked followed by the "Mod" operator to get the leftover minutes.

I'm having a logic problem calculating weekly pay. It's able to do it great with just an even hour number but I can't seem to have it figure out the additional pay with the leftover minutes it just multiplies it all together and get a giant number which is wrong.

Here is the code:

Dim strHoursWorked As String
Dim intHoursWorked As Integer
Dim strMinutesLeftover As String
Dim decMinutesLeftover As Decimal
Dim strPayRate As String
Dim decPayRate As Decimal

strHoursWorked = Me.txtMins.Text
intHoursWorked = Convert.ToInt32(strHoursWorked)
strMinutesLeftover = Me.txtMins.Text
decMinutesLeftover = Convert.ToDecimal(strMinutesLeftover)

strPayRate = Me.txtHourlyRate.Text
decPayRate = Convert.ToDecimal(strPayRate)

Me.lblHours.Text = intHoursWorked \ 60
Me.lblMinutes.Text = decMinutesLeftover Mod 60
help here >>Me.lblDollars.Text =
 
Hallo,

Have you tried:
((Me.lblMinutes.Text + 60 * Me.lblHours.Text) * strPayRate) / 60
Not sure how string arithmetic works, but using the string values displayed to the user can be a good idea as you won't get any 'funnies' with rounding errors.

- Frink
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top