EighterFromDecatur
New Member
- Joined
- Aug 27, 2011
- Messages
- 2
I want to be able to enter minutes and seconds without colon (730 instead of 7:30). My code to convert to a serial time value seems to be working, but I'm having problems formatting the output. When I try to suppress the hour, the minute is always 12. Why?
Sub TimeConv()
Dim str As String, t As Integer, mm As Integer, ss As Integer, mmSerial As Double, ssSerial As Double, tSerial As Double
str = InputBox("Enter a time without punctuation (Example: For 7 minutes, 30 seconds, enter '730'):")
If str <> "" Then t = CLng(str) Else Exit Sub
mm = Int(t / 100)
ss = t - (mm * 100)
mmSerial = mm / 1440
ssSerial = ss / 86400
tSerial = mmSerial + ssSerial
MsgBox "You entered: " & t & vbCr & _
"mm: " & Format(mm, "00") & " ss: " & Format(ss, "00") & vbCr & _
"Serial Minute: " & mmSerial & vbCr & _
"Serial Second: " & ssSerial & vbCr & _
"Serial Time (mm + ss): " & tSerial & vbCr & _
"Format hh:mm:ss: " & Format(tSerial, "hh:mm:ss") & vbCr & _
"Format [hh:]mm:ss: " & Format(tSerial, "[hh:]mm:ss") & vbCr & _
"Format mm:ss: " & Format(tSerial, "mm:ss"), _
vbInformation + vbOKOnly, "Date and Time"
End Sub
Sub TimeConv()
Dim str As String, t As Integer, mm As Integer, ss As Integer, mmSerial As Double, ssSerial As Double, tSerial As Double
str = InputBox("Enter a time without punctuation (Example: For 7 minutes, 30 seconds, enter '730'):")
If str <> "" Then t = CLng(str) Else Exit Sub
mm = Int(t / 100)
ss = t - (mm * 100)
mmSerial = mm / 1440
ssSerial = ss / 86400
tSerial = mmSerial + ssSerial
MsgBox "You entered: " & t & vbCr & _
"mm: " & Format(mm, "00") & " ss: " & Format(ss, "00") & vbCr & _
"Serial Minute: " & mmSerial & vbCr & _
"Serial Second: " & ssSerial & vbCr & _
"Serial Time (mm + ss): " & tSerial & vbCr & _
"Format hh:mm:ss: " & Format(tSerial, "hh:mm:ss") & vbCr & _
"Format [hh:]mm:ss: " & Format(tSerial, "[hh:]mm:ss") & vbCr & _
"Format mm:ss: " & Format(tSerial, "mm:ss"), _
vbInformation + vbOKOnly, "Date and Time"
End Sub
Last edited: