Private Sub Calculate_Click()
Dim Minutes As Long
Dim Seconds As Double
Dim Point As Double
Dim TotalSeconds As Double
Dim Temp() As String
Dim sTime As String
' ---------------------------------------------------------------------------------------------
' Convert first Time TextBox
' ---------------------------------------------------------------------------------------------
sTime = Me.Time1.Text
Minutes = 0
Seconds = 0#
If Not Me.Time1.Text = VBA.Constants.vbNullString Then
Temp = VBA.Strings.Split(sTime, ":")
If (UBound(Temp) - LBound(Temp) + 1) = 2 Then
On Error Resume Next
Minutes = VBA.Conversion.CLng(Temp(0))
Seconds = VBA.Conversion.CDbl(Temp(1))
On Error GoTo 0
TotalSeconds = TotalSeconds + Minutes * 60 + Seconds
End If
End If
' ---------------------------------------------------------------------------------------------
' Convert second Time TextBox
' ---------------------------------------------------------------------------------------------
sTime = Me.Time2.Text
Minutes = 0
Seconds = 0#
If Not Me.Time2.Text = VBA.Constants.vbNullString Then
Temp = VBA.Strings.Split(sTime, ":")
If (UBound(Temp) - LBound(Temp) + 1) = 2 Then
On Error Resume Next
Minutes = VBA.Conversion.CLng(Temp(0))
Seconds = VBA.Conversion.CDbl(Temp(1))
On Error GoTo 0
TotalSeconds = TotalSeconds + Minutes * 60 + Seconds
End If
End If
' ---------------------------------------------------------------------------------------------
' Convert third Time TextBox
' ---------------------------------------------------------------------------------------------
sTime = Me.Time3.Text
Minutes = 0
Seconds = 0#
If Not Me.Time3.Text = VBA.Constants.vbNullString Then
Temp = VBA.Strings.Split(sTime, ":")
If (UBound(Temp) - LBound(Temp) + 1) = 2 Then
On Error Resume Next
Minutes = VBA.Conversion.CLng(Temp(0))
Seconds = VBA.Conversion.CDbl(Temp(1))
On Error GoTo 0
TotalSeconds = TotalSeconds + Minutes * 60 + Seconds
End If
End If
' ---------------------------------------------------------------------------------------------
' Convert fourth Time TextBox
' ---------------------------------------------------------------------------------------------
sTime = Me.Time4.Text
Minutes = 0
Seconds = 0#
If Not Me.Time4.Text = VBA.Constants.vbNullString Then
Temp = VBA.Strings.Split(sTime, ":")
If (UBound(Temp) - LBound(Temp) + 1) = 2 Then
On Error Resume Next
Minutes = VBA.Conversion.CLng(Temp(0))
Seconds = VBA.Conversion.CDbl(Temp(1))
On Error GoTo 0
TotalSeconds = TotalSeconds + Minutes * 60 + Seconds
End If
End If
' ---------------------------------------------------------------------------------------------
' Convert it all into a displayable MM:SS.SS format
' ---------------------------------------------------------------------------------------------
'MsgBox "Total Seconds = " & TotalSeconds
Minutes = WorksheetFunction.RoundDown(TotalSeconds / 60, 0)
Seconds = TotalSeconds Mod 60
Point = TotalSeconds - ((Minutes * 60) + Seconds)
Seconds = Seconds + Point
Me.TotalTime.Text = VBA.Strings.Format(Minutes, "00") & ":" & VBA.Strings.Format(Seconds, "00.00")
End Sub