Time Code

  • Thread starter Thread starter Bruce Rodtnick
  • Start date Start date
B

Bruce Rodtnick

I have a form that I want to at Time Code into (Time Code is a feature
of video). Time Code looks similar to the regular time entry, i.e.
12:23:44, but it is entered from the right (1 then 2 then 2 then 3,etc,
moving each number to the left) and it might not use all the positions,
i.e. 23:44. Is there a way to do this and have the colon automatically
be inserted in the right place?

Bruce Rodtnick
 
I have a form that I want to at Time Code into (Time Code is a feature
of video). Time Code looks similar to the regular time entry, i.e.
12:23:44, but it is entered from the right (1 then 2 then 2 then 3,etc,
moving each number to the left) and it might not use all the positions,
i.e. 23:44. Is there a way to do this and have the colon automatically
be inserted in the right place?

Bruce Rodtnick

Paste this function into your form module. (watch for line wrap)
On the AfterUpdate event of your TimeCode control put -
Me.TimeCode = fAddColons(Me.TimeCode)
(change TimeCode to the name of your control)

'========================================
Function fAddColons(strIn As String) As String

If InStr(1, strIn, ":") = 0 Then 'has no colons
Select Case Len(strIn)
Case Is = 6
fAddColons = Left(strIn, 2) & ":" & Mid(strIn, 3, 2) & ":" &
Right(strIn, 2)
Case Is = 5
fAddColons = Left(strIn, 1) & ":" & Mid(strIn, 3, 2) & ":" &
right(strIn, 2)
Case Is = 4
fAddColons = Left(strIn, 2) & ":" & Right(strIn, 2)
Case Is = 3
fAddColons = Left(strIn, 1) & ":" & Right(strIn, 2)
Case Else
fAddColons = strIn
End Select
Else 'already has colons
fAddColons = strIn
End If

End Function
'========================================

From the debug window
?fAddColons("122344")
12:23:44

Wayne Gillespie
Gosford NSW Australia
 
I like the approach. I've put it all in but it doesn't do anything. I don't
understand your statement:

From the debug window
?fAddColons("122344")
12:23:44

I didn't do anything with that because I don't know where to put it. I'm running
2000.

My adjusted code is:

Private Sub txtTC_In_AfterUpdate()
Me.txtTC_In = fAddColons(Me.txtTC_In)
End Sub

Thanks for your help.

Bruce Rodtnick
 
Never mind. It's working great. Thanx.

B

Wayne said:
Paste this function into your form module. (watch for line wrap)
On the AfterUpdate event of your TimeCode control put -
Me.TimeCode = fAddColons(Me.TimeCode)
(change TimeCode to the name of your control)

'========================================
Function fAddColons(strIn As String) As String

If InStr(1, strIn, ":") = 0 Then 'has no colons
Select Case Len(strIn)
Case Is = 6
fAddColons = Left(strIn, 2) & ":" & Mid(strIn, 3, 2) & ":" &
Right(strIn, 2)
Case Is = 5
fAddColons = Left(strIn, 1) & ":" & Mid(strIn, 3, 2) & ":" &
right(strIn, 2)
Case Is = 4
fAddColons = Left(strIn, 2) & ":" & Right(strIn, 2)
Case Is = 3
fAddColons = Left(strIn, 1) & ":" & Right(strIn, 2)
Case Else
fAddColons = strIn
End Select
Else 'already has colons
fAddColons = strIn
End If

End Function
'========================================

From the debug window
?fAddColons("122344")
12:23:44

Wayne Gillespie
Gosford NSW Australia
 
I like the approach. I've put it all in but it doesn't do anything. I don't
understand your statement:

From the debug window
?fAddColons("122344")
12:23:44

This was just an example of the output of the function. If you open the debug
(immediate) window , by pressing <Ctrl>+G, and type ?fAddColons("122344") and
press enter, it will run the function and print the result 12:23:44. It's just
an easy way to test the function, you don't need to copy this to your db.
I didn't do anything with that because I don't know where to put it. I'm running
2000.

My adjusted code is:

Private Sub txtTC_In_AfterUpdate()
Me.txtTC_In = fAddColons(Me.txtTC_In)
End Sub

Thanks for your help.

Bruce Rodtnick

Glad to help.


Wayne Gillespie
Gosford NSW Australia
 
Back
Top