Input times with leading zeros

A

ancient_hilly

Hello, I have a race results program for a charity which needs changing.
The race is longer this year so I need to include hours (as well as mins and
seconds) to be stored in the format "01:23:45" so that fastest times can be
listed.
I want to keep data inputting to the minimum for speed, so that when a time
is, say, 24:35 I will not have to type in the leading zeros for the hours.
I've tried all sorts of masks and data types, but no success so far. Can
anyone please suggest a solution?
Thank you.
 
A

ancient_hilly

Dear Klatuu
Thank you for this. I can't try it out until late tomorrow, but it looks
great. I'll let you know how it works out.
 
K

Klatuu

Here is a function that should do most of what you need. It does not handle
hours over 99, nor does is check to see if mintues or seconds <= 60. I have
also coded it for the very best data entry speed. Instead of using the ":"
character for data entry, I have it set up to use "/". this way, the data
entry person does not have to go to the alpha keyboard, hold shift and enter
":", the "/" i on the number keypad and easy to get to. Also, nothing has to
have leading zeros. You can enter "3/3/2"
(Three Hours, Three Minutes, and Two Seconds) it will print as "03:03:02"

call it like Me.txtTimeBox = FormatTime(me.txtTimeBox)

Function FormatTime(strTime As String) As String
Dim aryTime
aryTime = Split(strTime, "/")
Select Case UBound(aryTime)
Case Is = 0
FormatTime = "00:00:" & Format(aryTime(0), "00")
Case Is = 1
FormatTime = "00:" & Format(aryTime(0), "00") & ":" &
Format(aryTime(1), "00")
Case Is = 2
FormatTime = Format(aryTime(0), "00") & ":" _
& Format(aryTime(1), "00") & ":" & Format(aryTime(2), "00")
End Select
End Function


Put it in the Lost Focust or Before Update event of your text box, depending
 
K

Klatuu

Post all the code in the Finish Time Before Update Event. It is just a
matter of syntax. I will be happy to fix it for you.

ancient_hilly said:
Hello Klatuu
Sorry but I'm having problems making this function work. I'm sure it's
because I am not familiar with how to set up functions. But this is what I
did.

From the property sheet of the text field [FinishTime] I clicked on the Code
Builder option for the Before Update property and this led me to a section
like this
-----

Private Sub FinishTime_BeforeUpdate(Cancel As Integer)

End Sub
-----

When I pasted your text between these two lines an extra End Function
appeared at the end and the End Sub disappeared.

When I typed into the FinishTime field on the saved form I got the error:
Compile Error: Method or Data Member Not Found

The following line was highlighted:
Private Sub FinishTime_BeforeUpdate(Cancel As Integer)

And the (Me.txtTimeBox) part of the following line was also highlighted
Me.txtTimeBox = FormatTime(Me.txtTimeBox)

I tried renaming things and chopping things out but I get all kinds of other
errors. As I say, I don't really know what I'm doing working on the code
side of things.

Can you offer any further help, or should I abandon this route, please? Thanks
ancient_hilly



Klatuu said:
Here is a function that should do most of what you need. It does not handle
hours over 99, nor does is check to see if mintues or seconds <= 60. I have
also coded it for the very best data entry speed. Instead of using the ":"
character for data entry, I have it set up to use "/". this way, the data
entry person does not have to go to the alpha keyboard, hold shift and enter
":", the "/" i on the number keypad and easy to get to. Also, nothing has to
have leading zeros. You can enter "3/3/2"
(Three Hours, Three Minutes, and Two Seconds) it will print as "03:03:02"

call it like Me.txtTimeBox = FormatTime(me.txtTimeBox)

Function FormatTime(strTime As String) As String
Dim aryTime
aryTime = Split(strTime, "/")
Select Case UBound(aryTime)
Case Is = 0
FormatTime = "00:00:" & Format(aryTime(0), "00")
Case Is = 1
FormatTime = "00:" & Format(aryTime(0), "00") & ":" &
Format(aryTime(1), "00")
Case Is = 2
FormatTime = Format(aryTime(0), "00") & ":" _
& Format(aryTime(1), "00") & ":" & Format(aryTime(2), "00")
End Select
End Function


Put it in the Lost Focust or Before Update event of your text box, depending
 
A

ancient_hilly

Hello Klatuu
Sorry but I'm having problems making this function work. I'm sure it's
because I am not familiar with how to set up functions. But this is what I
did.

From the property sheet of the text field [FinishTime] I clicked on the Code
Builder option for the Before Update property and this led me to a section
like this
-----

Private Sub FinishTime_BeforeUpdate(Cancel As Integer)

End Sub
-----

When I pasted your text between these two lines an extra End Function
appeared at the end and the End Sub disappeared.

When I typed into the FinishTime field on the saved form I got the error:
Compile Error: Method or Data Member Not Found

The following line was highlighted:
Private Sub FinishTime_BeforeUpdate(Cancel As Integer)

And the (Me.txtTimeBox) part of the following line was also highlighted
Me.txtTimeBox = FormatTime(Me.txtTimeBox)

I tried renaming things and chopping things out but I get all kinds of other
errors. As I say, I don't really know what I'm doing working on the code
side of things.

Can you offer any further help, or should I abandon this route, please? Thanks
ancient_hilly
 
Top