MattBaldry
Self Taught, Learn from the Forums
- Local time
 - Today, 08:51
 
- Joined
 - Feb 5, 2019
 
- Messages
 - 365
 
Hello coding wizards,
Is anyone out there able to add seconds to the below code?
	
	
	
		
https://extramiledata.com/get-total-hours-and-minutes-from-summing-columns-of-hours-and-minutes/
I have been trying all afternoon and just cannot get it to work
I am trying to get the below columns to show correctly.
Total Hours: [LabourResourceHours]*([QtyRequired]*[PieceWorkQuantity])
Total Minutes: [LabourResourceMinutes]*([QtyRequired]*[PieceWorkQuantity])
Total Seconds: [LabourResourceSeconds]*([QtyRequired]*[PieceWorkQuantity])
Like the 4,200 seconds should display as 1 hours, 10 minutes, 0 seconds
~Matt
 Is anyone out there able to add seconds to the below code?
		Code:
	
	
	Public Function CalcHoursOrMinutes(CalcType As String, Hours, Minutes)
' This procedure calculates the values for the CalcType, "Hours" or "Minutes".
' If either Hours or Minutes is Null, the function returns Null.
On Error GoTo Err_Handler
' CalcHoursOrMinutes() Version 1.0.0
' Copyright © 2013 Extra Mile Data, www.extramiledata.com.
' For questions or issues, please contact support@extramiledata.com.
' Use (at your own risk) and modify freely as long as proper credit is given.
    Dim lngTotalMinutes As Long
    Dim lngHours As Long
    Dim lngMinutes As Long
    ' Clear the values and exit if some of the calculation values are null.
    If IsNull(Hours) And IsNull(Minutes) Then
        CalcHoursOrMinutes = Null
        GoTo Exit_Proc
    End If
    ' Get the total minutes.
    lngTotalMinutes = (Nz(Hours, 0) * 60) + Nz(Minutes, 0)
    ' Get the hours.
    lngHours = Int(lngTotalMinutes / 60)
    ' Get the minutes.
    lngMinutes = lngTotalMinutes - (lngHours * 60)
    If CalcType = "Hours" Then
        CalcHoursOrMinutes = lngHours
    Else
        CalcHoursOrMinutes = lngMinutes
    End If
Exit_Proc:
    On Error Resume Next
    Exit Function
Err_Handler:
    MsgBox Err.Number & " " & Err.Description, vbInformation, _
        "CalcHoursOrMinutes()"
    CalcHoursOrMinutes = Null
    Resume Exit_Proc
	https://extramiledata.com/get-total-hours-and-minutes-from-summing-columns-of-hours-and-minutes/
I have been trying all afternoon and just cannot get it to work
I am trying to get the below columns to show correctly.
Total Hours: [LabourResourceHours]*([QtyRequired]*[PieceWorkQuantity])
Total Minutes: [LabourResourceMinutes]*([QtyRequired]*[PieceWorkQuantity])
Total Seconds: [LabourResourceSeconds]*([QtyRequired]*[PieceWorkQuantity])
Like the 4,200 seconds should display as 1 hours, 10 minutes, 0 seconds
| Total Hours | Total Minutes | Total Seconds | 
|---|---|---|
0  | 0  | 0  | 
0  | 0  | 0  | 
0  | 140  | 2100  | 
0  | 0  | 4200  | 
0  | 0  | 0  | 
0  | 140  | 0  | 
0  | 210  | 0  | 
0  | 0  | 4200  | 
0  | 0  | 840  | 
0  | 0  | 2100  | 
0  | 140  | 0  | 
0  | 0  | 840  | 
0  | 0  | 0  | 
~Matt
			
				Last edited: