Output to file on disk in windows 10

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

Output to file on disk in windows 10

Postby Kees van Dongen » Sep 17, 2020 17:33

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

Re: Output to file on disk in windows 10

Postby Imortis » Sep 17, 2020 17:57

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: 2148
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Output to file on disk in windows 10

Postby badidea » Sep 17, 2020 21:40

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: 3308
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: Output to file on disk in windows 10

Postby coderJeff » Sep 18, 2020 2:08

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: 8162
Joined: May 28, 2005 3:28
Contact:

Re: Output to file on disk in windows 10

Postby D.J.Peters » Sep 19, 2020 10:58

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

Postby Kees van Dongen » Sep 19, 2020 18:34

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

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 2 guests