# srt routine working so far...

This routine seems able to add any time in milliseconds, to 1 subtitle inside an srt file (change lag%).

DECLARE SUB DELAY (srt\$, lag&)

TYPE srttime
hr AS LONG
mn AS LONG
sc AS LONG
msc AS LONG
END TYPE

DIM SHARED subt(2) AS srttime
DIM SHARED srt(2) AS STRING
DIM SHARED srtmsc(2) AS LONG

srt\$ = "01:33:32,700 --> 01:33:35,603"

CLS

lag& = 50000

CALL DELAY(srt\$, lag&)

END

ERRORHANDLE:
PRINT "ERROR"
RESUME NEXT

'////////////////// SUB /////////////////

SUB DELAY (srt\$, lag&)

'parse the string

c% = INSTR(srt\$, "-->")
srt(1) = LEFT\$(srt\$, c% - 2)
srt(2) = RIGHT\$(srt\$, LEN(srt\$) - (c% + 3))

FOR i = 1 TO 2

subt(i).hr = VAL(LEFT\$(srt(i), 2))
subt(i).mn = VAL(MID\$(srt(i), 4, 2))
subt(i).sc = VAL(MID\$(srt(i), 7, 2))
subt(i).msc = VAL(MID\$(srt(i), 10, 3))

NEXT i

FOR i = 1 TO 2

PRINT subt(i).hr
PRINT subt(i).mn
PRINT subt(i).sc
PRINT subt(i).msc

NEXT i

PRINT

'convert to to milisec :

ON ERROR GOTO ERRORHANDLE

FOR i = 1 TO 2
srtmsc(i) = subt(i).msc + (subt(i).sc + subt(i).mn * 60 + subt(i).hr * 3600) * 1000
PRINT srtmsc(i)
NEXT i

PRINT

FOR i = 1 TO 2
srtmsc(i) = srtmsc(i) + lag&
NEXT i

'converting back to srt time format :

FOR i = 1 TO 2

subt(i).msc = srtmsc(i) MOD 1000
srtmsc(i) = srtmsc(i) - subt(i).msc
srtmsc(i) = INT(srtmsc(i) / 1000)

subt(i).sc = srtmsc(i) MOD 60
srtmsc(i) = srtmsc(i) - subt(i).sc

subt(i).hr = INT(srtmsc(i) / 3600)
srtmsc(i) = srtmsc(i) - subt(i).hr * 3600

subt(i).mn = INT(srtmsc(i) / 60)

NEXT i

FOR i = 1 TO 2

PRINT subt(i).hr
PRINT subt(i).mn
PRINT subt(i).sc
PRINT subt(i).msc

NEXT i

END SUB

Posted on May 28, 2012, 3:12 PM

 Response Title Author and Date SRTDELAY.BAS working lisztfr on May 31 SRTDELAY.BAS optimized, UDT passed to sub lisztfr on Jun 1