Output to file on disk in windows 10

New to FreeBASIC? Post your questions here.
Post Reply
Kees van Dongen
Posts: 2
Joined: Sep 17, 2020 17:07

Output to file on disk in windows 10

Post by Kees van Dongen »

Print and print#1 or print#2 etc all output to screen in stead off diskfile, what's wrong?
Imortis
Moderator
Posts: 1924
Joined: Jun 02, 2005 15:10
Location: USA
Contact:

Re: Output to file on disk in windows 10

Post by Imortis »

If you post your code, we might be able to help you more easily. As it is, there is not enough info to give you a definitive answer.
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Output to file on disk in windows 10

Post by badidea »

An example use:

Code: Select all

dim as string fileName1 = "test_file_1.txt"
dim as string fileName2 = "test_file_2.txt"

if open(fileName1 for output as #1) <> 0 then
	print "Error opening: " & fileName1
	end 'closes all open files as well
else
	print "File created: " & fileName1
end if

if open(fileName2 for output as #2) <> 0 then
	print "Error opening: " & fileName2
	end 'closes all open files as well
else
	print "File created: " & fileName2
end if

print #1, "Test 111"
close #1

print #2, "Test 222"
close #2

end 'closes all open files as well
For more info see: Wiki: (PRINT | ?) #
coderJeff
Site Admin
Posts: 4326
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Output to file on disk in windows 10

Post by coderJeff »

Hello Kees van Dongen.

Choose the "POST REPLY" button bottom left of page to respond.

The "Report Post" Button is for something else - you don't want that one.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Output to file on disk in windows 10

Post by D.J.Peters »

Kees van Dongen wrote:print#1 or print#2 etc all output to screen ...
There must be a space between print and the file number !

wrong:

Code: Select all

print#1 
print#2 
sleep
OK:

Code: Select all

print #1,your_data_or_var 
print #2,your_data_or_var
Interesting:
print#1 outputs "1"
print#2 outputs "2"
you can interpret it as fbc print the file number "1" and "2" but for me it looks like a tiny parsing bug ?

Joshy
Kees van Dongen
Posts: 2
Joined: Sep 17, 2020 17:07

Re: Output to file on disk in windows 10

Post by Kees van Dongen »

Thanks to all, it was a mistake of a former life with PB. A space was the problem.
Post Reply