Hi,
I have written this procedure that converts decimal time (1.75) into analogue time (1hr 45 mins). It works ok, but seems a little verbose. Any suggestions for making it more efficient and shorter?
Regards,
I have written this procedure that converts decimal time (1.75) into analogue time (1hr 45 mins). It works ok, but seems a little verbose. Any suggestions for making it more efficient and shorter?
Regards,
Code:
Sub testString()
Dim Duration As String
Dim hrs As String, mins As String, totTime as String
'set Duration to decimal time
Duration = "1.75"
If Len(Duration) = 3 Then
totTime = Duration * 60 & “mins”
ElseIf Len(Duration) = 4 then
Hrs=Left(Duration, Len(Duration) – 3)
Mins = Right(Duration, Len(Duration) – 1) * 60
If hrs = “1” Then
totTime = hrs & “hr “ & mins & “mins”
else
totTime = hrs & “hrs “ & mins & “mins”
end if
ElseIf Len(Duration) = 5 Then
Hrs = Left(Duration, Len(Duration) – 3)
Mins = Right(Duration, Len(Duration) – 2) * 60
totTime = hrs & “hrs “ & mins & “mins”
Else
'could be hundreds of hours
Hrs = Left(Duration, Len(Duration) – 3)
Mins = Right(Duration, Len(Duration) – 3) * 60
totTime = hrs & “hrs “ & mins & “mins”
End If
MsgBox totTime
End Sub