Code: Select all
PrintC #f, "text"; "text2" & "text3", data
Code: Select all
Print #f, "text"; "text2" & "text3", data
Print "text"; "text2" & "text3", data
Code: Select all
#macro PrintC( a, b... )
Print a, b
Print b
#end macro
Code: Select all
PrintC #f, "text"; "text2" & "text3", data
Code: Select all
Print #f, "text"; "text2" & "text3", data
Print "text"; "text2" & "text3", data
Code: Select all
#macro PrintC( a, b... )
Print a, b
Print b
#end macro
Code: Select all
#macro PrintC( a, b... )
Print a, b
Print b
#endmacro
Dim bdata as byte = 41
dim f as long
f = freefile
open "c:\temp\junk.txt" for output as #f
PrintC( #f, "text"; "text2" & "text3", bdata )
close #f
sleep
Code: Select all
#include "file.bi"
#define printC( stuff... ) print stuff
Dim bdata as byte = 41
dim f as long
f = freefile
open "junk.txt" for output as #f
PrintC( #f, "text "; "text2" & "text3", bdata,chr(10)+"File status:" )
close #f
shell "type junk.txt"
kill "junk.txt"
printc (iif(fileexists("junk.txt"),"Goodbye, press any key, delete file manually","Goodbye, press any key, file deleted"))
sleep
Code: Select all
'' replace 'print' behaviour so that any print to a file will also print same text to screen
'' undefine 'print' so we can replace it
'' trick is: we can still use '?' for the built-in print.
#undef print
'' ignore the file number and print to console
#macro print_skip_filenum( filenum, stuff... )
? stuff
#endmacro
'' PRINT [#filenum,] ...
'' perform 'print' as-is or if it writes to a file number, then also print to console
'' in this context, the '?' makes the parens '(' and ')' optional to use
#macro print ? ( stuff... )
'' could be to console or file so print as-is
? stuff
'' starts with #filenum? then also print to console
#if (__fb_arg_count__(stuff) > 1) andalso (asc(__fb_quote__((stuff)),2) = asc("#"))
print_skip_filenum( stuff )
#endif
#endmacro
dim bdata as byte = 41
dim f as long = freefile
print "TEST:" '' screen only
print "------------"
open "junk.txt" for output as #f
print #f, "START" '' screen and file
print #f, "print to both file and screen"
print #f, '' blank line
print #f,, '' tab indent
print #f, "tab indent"
print #f, "text1 "; "text2 " & "text3 ", bdata, chr(10) + "File status: ";
print #f, "DONE"
print #f, "END"
close #f
print "------------"
print
print
print "RESULTS:"
print "------------"
shell "type junk.txt"
kill "junk.txt"
print "------------"
sleep
Code: Select all
#include "file.bi"
#define printC( filenumber,stuff... ) print filenumber,stuff: print stuff
Dim bdata As Byte = 41
Dim f As Long
color 4
f = Freefile
Open "junk.txt" For Output As #f
PrintC( #f, "text "; "text2" & "text3", bdata)
Close #f
Color 15
Shell "type junk.txt"
Kill "junk.txt"
Print Iif(Fileexists("junk.txt"),"Goodbye, press any key, delete file manually","Goodbye, press any key, file deleted")
Sleep
I don't understand. Which trick? And why the expectation it won't work in future? If we intentionally break user code in a future release it should be justified - of course opinions vary.
Code: Select all
Command executed:
"C:\FreeBASIC\fbc.exe" "C:\FreeBASIC\FBIDE\FBIDETEMP.bas"
Compiler output:
C:\FreeBASIC\FBIDE\FBIDETEMP.bas(27) error 42: Variable not declared, stuff in 'print "TEST:" '' screen only'
C:\FreeBASIC\FBIDE\FBIDETEMP.bas(27) error 3: Expected End-of-Line, found 'stuff' in 'print "TEST:" '' screen only'
C:\FreeBASIC\FBIDE\FBIDETEMP.bas(27) error 7: Expected ')', found '(' in 'print "TEST:" '' screen only'
C:\FreeBASIC\FBIDE\FBIDETEMP.bas(28) error 9: Expected expression, found 'stuff' in 'print "------------"'
C:\FreeBASIC\FBIDE\FBIDETEMP.bas(28) error 3: Expected End-of-Line, found 'stuff' in 'print "------------"'
C:\FreeBASIC\FBIDE\FBIDETEMP.bas(28) error 7: Expected ')', found '(' in 'print "------------"'
C:\FreeBASIC\FBIDE\FBIDETEMP.bas(30) error 9: Expected expression, found 'stuff' in 'print #f, "START" '' screen and file'
C:\FreeBASIC\FBIDE\FBIDETEMP.bas(30) error 3: Expected End-of-Line, found 'stuff' in 'print #f, "START" '' screen and file'
C:\FreeBASIC\FBIDE\FBIDETEMP.bas(30) error 7: Expected ')', found '(' in 'print #f, "START" '' screen and file'
C:\FreeBASIC\FBIDE\FBIDETEMP.bas(31) error 9: Expected expression, found 'stuff' in 'print #f, "print to both file and screen"'
C:\FreeBASIC\FBIDE\FBIDETEMP.bas(31) error 133: Too many errors, exiting
Results:
Compilation failed
System:
FBIde: 0.4.6
fbc: FreeBASIC Compiler - Version 1.07.1 (2019-09-27), built for win32 (32bit)
OS: Windows NT 6.2 (build 9200)
Code: Select all
C:\FreeBASIC>fbc32 -version
FreeBASIC Compiler - Version 1.10.0 (2023-05-14), built for win32 (32bit)
Copyright (C) 2004-2023 The FreeBASIC development team.
standalone