Program runs great, but no outputfile on disc

Windows specific questions.
Post Reply
Ronnay
Posts: 1
Joined: Mar 28, 2022 9:55

Program runs great, but no outputfile on disc

Post by Ronnay »

I've written this program to convert timestamps in a video subtitles file.
The program compiles without errors in an administrators cmd screen.
D:\FreeBASIC>fbc.exe -lang qb d:\subsdir\convert-subs.bas

D:\FreeBASIC>cd \subsdir

D:\subsdir>convert-subs.exe

D:\subsdir>

And as seen above runs without (visible) errors.
However, there is no file created (if output file does not exist) or updated (if output file exists).

If I uncomment the print regel2 statement for converted lines, all looks great.
What is wrong in the sourcecode below, or why isn't the new file created/updated?

Code: Select all

rem Program to convert 2 timeformats on some lines in text files
rem All timestamps should be 59 seconds less
rem example:
rem file_to_convert.org.txt                     file_to_convert.new.txt 
rem 0001  1                                     0001  1
rem 0002  00:01:24,776 --> 00:01:26,176         0002  00:00:15,776 --> 00:00:17,176
rem 0003  Hello.                                0003  Hello.
rem 0004                                        0004  
rem 0005  2                                     0005  2
rem 0006  00:01:29,936 --> 00:01:33,877         0006  00:00:20,936 --> 00:00:24,877
rem 0007  Hello!                                0007  Hello!
rem 0008  - Oh, hi.                             0008  - Oh, hi.
rem 0009                                        0009  
rem 0010  3                                     0010  3
rem 0011  00:01:34,337 --> 00:01:35,697         0011  00:00:25,337 --> 00:00:26,697
rem 0012  Nice wether.                          0012  Nice wether.
rem

dim as string regel1, regel2, tijd, mins, secs
dim as integer mini, seci, newtijd
dim as long file_num1, file_num2

file_num1 = FreeFile()
file_num2 = FreeFile()

Open "d:\subsdir\file_to_convert.org.txt" For Input As #file_num1
Open "d:\subsdir\file_to_convert.new.txt" For Output As #file_num2

DO Until EOF(file_num1)
  Line Input #file_num1, regel1
	IF left$(regel1, 3) = "00:" THEN
	  tijd = mid$(regel1, 4, 5)
    gosub converttijd
		regel2 = "00:" + tijd + mid$(regel1, 9, 12)
	  tijd = mid$(regel1, 21, 5)
    gosub converttijd
		regel2 = regel2 + tijd + right$(regel1, 4)
rem print regel2
    print #file_num2, regel2
	ELSE
	  print #file_num2, regel1
	END IF
Loop
close #file_num1, #file_num2
END


converttijd:
mini = val(left$(tijd, 2))
seci = val(right$(tijd, 2))
newtijd = (mini * 60) + seci - 59
mini = newtijd / 60
mins = mid$(str$(mini),2,2)
if len(mins) = 1 then 
  mins = "0" + mins
end if
seci = newtijd mod 60
secs = mid$(str$(seci),2,2)
if len(secs) = 1 then
  secs = "0" + secs
end if
tijd = mins + ":" + secs
return
Imortis
Moderator
Posts: 1923
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: Program runs great, but no outputfile on disc

Post by Imortis »

If you put a print statement after your freefile() lines you will see that both file_num1 and file_num2 have the same handle. Get the first freefile, open the first file, then get the second freefile, then open the second file.
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Program runs great, but no outputfile on disc

Post by fxm »

Yes, it's well described in the FREEFILE documentation page:
..... it is wise to use Freefile immediately before its corresponding Open, to ensure that the same file number is not returned and opened elsewhere first.
.....
Post Reply