Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding two whole numbers to display as time value 1

Status
Not open for further replies.

loobzer

Programmer
Mar 27, 2002
5
US
I'm not much of a programmer and would greatly appreciate any advice anyone has to offer on this formula problem I'm having. I have two data fields that represent time values but are stored as whole numbers:

SEGSTART - The starting time code of a program segment on a video tape (how much time into the tape the program starts)
SEGLEN - The total duration of the same program segment on the tape

What I'm trying to do is to calculate the ending time of the program segment on the video tape by adding the length of the segment to its start time. The times are stored as 8-digit numbers (hours/minutes/seconds/frames)

An example:

Duration Start Time: 10093000
Duration Length: 00054300

Because these time values are actually stored as whole numbers, these two fields added together total to 10147300 (hours=10, minutes=14, seconds=73, frames=00). What I'm trying to do is obviously to convert this value to a real-time value so it displays properly. It should read 10151300 (10:15:13:00)

The formula I'm using is below. If anyone could help me modify this to display the time values correctly, thanks in advance!

Formula is:

dim hh as Number
dim mm as Number
dim ss as Number
dim ff as Number

hh=Fix(({PGMVERSEG.SEGSTART}+{PGMVERSEG.SEGLEN}) / 1000000)
mm=Fix((({PGMVERSEG.SEGSTART}+{PGMVERSEG.SEGLEN}) mod 1000000)/10000)
ss=Fix((({PGMVERSEG.SEGSTART}+{PGMVERSEG.SEGLEN}) mod 10000)/100)
ff=Fix(({PGMVERSEG.SEGSTART}+{PGMVERSEG.SEGLEN}) mod 100)

rem if ff>24 then ff=ff-25 and ss=ss+1
rem if ss>59 then ss=ss-60 and mm=remainder(+1
rem if mm>59 then mm=mm-60 and hh=hh+1

Formula=ToText(hh,"00")+":"+ToText(mm,"00")+":"+ToText(ss,"00")+":"+ToText(ff,"00")
 
Here it is in Crystal Syntax:

Code:
stringvar start:={PGMVERSEG.SEGSTART};
stringvar dura:={PGMVERSEG.SEGLEN};
stringvar out;

numbervar ss:=val(mid(start,5,2));
numbervar sm:=val(mid(start,3,2));
numbervar sh:=val(left(start,2));
numbervar sf:=val(right(start,2));

numbervar ds:=val(mid(dura,5,2));
numbervar dm:=val(mid(dura,3,2));
numbervar dh:=val(Left(dura,2));
numbervar df:=val(right(dura,2));

numbervar outh;
numbervar outm;
numbervar outs;
numbervar outf;

if sf + df >24 then (outs:=1;outf:=sf+df-24) else outf:=sf+df;
if ss + ds + outs >= 60 then (outm:=1 ;outs:=outs + ss + ds -60) else outs:=outs + ss + ds;
if sm + dm + outm >= 60 then (outh:=1;outm:=outm + sm + dm - 60) else outm:=outm +sm + dm;
outh:=outh+sh+dh;

ToText(outh,"00")+":"+ToText(outm,"00")+":"+ToText(outs,"00")+":"+ToText(outf,"00")

I'm assuming that the fields are actually string fields and not numbers. My assupmtion is based on the fact that you have leading zeros in the duration.

Here it is in case you padded the duration field for your post:
Code:
numbervar startraw:=10093000;
numbervar duraraw:=00054300;
stringvar start;
stringvar dura;

start:=replicatestring("0",8-len(totext(startraw,0,"")))+totext(startraw,0,"");
dura:=replicatestring("0",8-len(totext(duraraw,0,"")))+totext(duraraw,0,"");


stringvar out;

numbervar ss:=val(mid(start,5,2));
numbervar sm:=val(mid(start,3,2));
numbervar sh:=val(left(start,2));
numbervar sf:=val(right(start,2));

numbervar ds:=val(mid(dura,5,2));
numbervar dm:=val(mid(dura,3,2));
numbervar dh:=val(Left(dura,2));
numbervar df:=val(right(dura,2));

numbervar outh;
numbervar outm;
numbervar outs;
numbervar outf;

if sf + df >24 then (outs:=1;outf:=sf+df-24) else outf:=sf+df;
if ss + ds + outs >= 60 then (outm:=1 ;outs:=outs + ss + ds -60) else outs:=outs + ss + ds;
if sm + dm + outm >= 60 then (outh:=1;outm:=outm + sm + dm - 60) else outm:=outm +sm + dm;
outh:=outh+sh+dh;

ToText(outh,"00")+":"+ToText(outm,"00")+":"+ToText(outs,"00")+":"+ToText(outf,"00")

Mike
 
Thanks Mike! The fields I'm using are actually numeric. I padded them with starting zeros in my original post. Sorry to confuse you. But from what I see, I think the second formula will work except that I need to reset it for each program segment on the video tape. It is currently doing the addition cumulatively for each successive segment. The fields are still in the details section but I've added a group based on the segment number, but I don't know how to go about resetting the formula for each segment. Here's what its doing (without the colons):

Segment Start Duration End (this formula)
1 10000000 00091300 10091300 (correct)
2 10093000 00054300 20152600 (not correct, adds values for segs 1-2)
3 10153000 00125400 30285000 (not correct, adds values for segs 1-3)
4 10285000 00072700 40366700 (not correct, adds values for segs 1-4)
5 10364000 00084900 50459600 (not correct, adds values for segs 1-5)

etc.

Thanks for your help so far!!



 
I realized you might have that problem last night when I was no where near a computer.

Change all of the variables to "Local"

For example, this:
Code:
numbervar ds:=val(mid(dura,5,2));
would be:
Code:
local numbervar ds:=val(mid(dura,5,2));


Mike
 
You rock Mike. It works great and thanks a million. I'd buy you a beer if you were here.

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top