Military Time

dualhcsniatpac

Board Regular
Joined
Feb 18, 2009
Messages
126
Code:
RcTime = CInt(Right(covertime.Value, 2))
LcTime = CInt(Left(covertime.Value, 2))
If RcTime < 0 Or RcTime > 59 Or LcTime < 0 Or LcTime > 24 Or covertime.Value > 2400 Then
    MsgBox "Please Enter in a Valid Time (0000-2400)", vbInformation, "Error Message"
    covertime.SetFocus
    Exit Sub
End If

Ok. I have a textbox where a user enters time (0000-2400). The above code will make sure that the user enters the right format.

My question is will it mess everything up if the user enters a time of 930 instead of 0930. My theory is that it will see the 2 integers as 93 and 30. If that is the case my code will reject their input and ask for another one even though it is correct.

Is there a way to detect if the integer is only 3 numbers and add a zero on. Or force the user to enter 4 numbers?

Thanks in advance.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Programaticaly add the leading 0's.

Code:
covertime.Value = Right("0000" & covertime.Value, 4)
RcTime = CInt(Right(covertime.Value, 2))
LcTime = CInt(Left(covertime.Value, 2))
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,617
Messages
6,120,541
Members
448,970
Latest member
kennimack

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top