I've been trying to create some VBA functions to calculate timecode entries.
Timecode is represented in the format:
hh:mm:ss:ff
Where hh = hours, mm = minutes, ss = seconds, and ff=frames
I am dealing with video that runs at 30 frames per second, so possible values for ff are 0 to 29.
In order to do simple arithmetic, I think the easiest thing is to translate any timecode entry to the total number of frames, do the arithmetic, then convert it back to timecode.
I'm trying to create VBA functions to do this for me.
Here's what I have so far:
Function NumFrames(TimeCodeCell As Range)
Dim hh As Integer
Dim mm As Integer
Dim ss As Integer
Dim ff As Integer
TimeCodeText = TimeCodeCell.Value
hh = Mid(TimeCodeText, 1, 2)
mm = Mid(TimeCodeText, 4, 2)
ss = Mid(TimeCodeText, 7, 2)
ff = Mid(TimeCodeText, 10, 2)
NumFrames = Frames + (ss * 30) + (mm * 30 * 60) + (hh * 30 * 60 * 60)
End Function
To get to the number of frames.
The problem is that it will only calculate up to 00:18:12:07 or 32,767 frames. After that point, I get #VALUE!.
I also need help with the reverse conversion.
So far I have:
Function TCString(NumFramesCell As Range)
Dim hh As Integer
Dim mm As Integer
Dim ss As Integer
Dim ff As Integer
NumFramesValue = NumFramesCell.Value
hh = Int(NumFramesValue / 30 / 60 / 60)
mm = Int((NumFramesValue - hh * 30 * 60 * 60) / 30 / 60)
ss = Int((NumFramesValue - (hh * 30 * 60 * 60 + mm * 30 * 60)) / 30)
ff = Int(NumFramesValue - (hh * 30 * 60 * 60 + mm * 30 * 60 + ss * 30))
TCString = CStr(hh) & ":" & CStr(mm) & ":" & CStr(ss) & ":" & CStr(ff)
End Function
This code has two problems. The first is the same as with NumFrames in that it won't calcualte more than 00:18:12:07 or 32,767 frames.
The second problem is in the string output. I need all three numbers to be two digit numbers even if that means a preceeding zero.
Thanks for your help.
<table style="border-collapse: collapse;" border="0" cellpadding="0" cellspacing="0" width="75"><tbody><tr height="13"><td class="xl24" x:num="32767.0" align="right" height="13" width="75">
</td> <!--EndFragment--> </tr> </tbody></table>
Timecode is represented in the format:
hh:mm:ss:ff
Where hh = hours, mm = minutes, ss = seconds, and ff=frames
I am dealing with video that runs at 30 frames per second, so possible values for ff are 0 to 29.
In order to do simple arithmetic, I think the easiest thing is to translate any timecode entry to the total number of frames, do the arithmetic, then convert it back to timecode.
I'm trying to create VBA functions to do this for me.
Here's what I have so far:
Function NumFrames(TimeCodeCell As Range)
Dim hh As Integer
Dim mm As Integer
Dim ss As Integer
Dim ff As Integer
TimeCodeText = TimeCodeCell.Value
hh = Mid(TimeCodeText, 1, 2)
mm = Mid(TimeCodeText, 4, 2)
ss = Mid(TimeCodeText, 7, 2)
ff = Mid(TimeCodeText, 10, 2)
NumFrames = Frames + (ss * 30) + (mm * 30 * 60) + (hh * 30 * 60 * 60)
End Function
To get to the number of frames.
The problem is that it will only calculate up to 00:18:12:07 or 32,767 frames. After that point, I get #VALUE!.
I also need help with the reverse conversion.
So far I have:
Function TCString(NumFramesCell As Range)
Dim hh As Integer
Dim mm As Integer
Dim ss As Integer
Dim ff As Integer
NumFramesValue = NumFramesCell.Value
hh = Int(NumFramesValue / 30 / 60 / 60)
mm = Int((NumFramesValue - hh * 30 * 60 * 60) / 30 / 60)
ss = Int((NumFramesValue - (hh * 30 * 60 * 60 + mm * 30 * 60)) / 30)
ff = Int(NumFramesValue - (hh * 30 * 60 * 60 + mm * 30 * 60 + ss * 30))
TCString = CStr(hh) & ":" & CStr(mm) & ":" & CStr(ss) & ":" & CStr(ff)
End Function
This code has two problems. The first is the same as with NumFrames in that it won't calcualte more than 00:18:12:07 or 32,767 frames.
The second problem is in the string output. I need all three numbers to be two digit numbers even if that means a preceeding zero.
Thanks for your help.
<table style="border-collapse: collapse;" border="0" cellpadding="0" cellspacing="0" width="75"><tbody><tr height="13"><td class="xl24" x:num="32767.0" align="right" height="13" width="75">
</td> <!--EndFragment--> </tr> </tbody></table>