Print vs Print #2, results with TAB different
Print vs Print #2, results with TAB different
I get different results when using the standard output Print vs. printing to a numbered file (i.e. Print #2,) when using TAB. For example, the following statement works placing the second item, a string, in the proper tab position (i.e. 50)
Print a(x,1);tab(50);s
However, the following Print statement seems to ignore the TAB function and prints at the usual default positions:
Print #2,a(x,1);tab(50);s
The documentation does not appear to state there are differences.
Print a(x,1);tab(50);s
However, the following Print statement seems to ignore the TAB function and prints at the usual default positions:
Print #2,a(x,1);tab(50);s
The documentation does not appear to state there are differences.
Re: Print vs Print #2, results with TAB different
For me this works:
Output:
"test.txt":
Code: Select all
Dim As Integer a(5, 2)
Dim As Integer x = 3
a(x, 1) = 123
Dim As String s = "fxm"
Print a(x,1); Tab(50); s
Open "test.txt" For Output As #2
Print #2, a(x,1); Tab(50); s
Close #2
Sleep
Code: Select all
123 fxm
Code: Select all
123 fxm
Re: Print vs Print #2, results with TAB different
Interesting. But by specifying CONS as output, mine doesn't.
Output:
Code: Select all
Dim As Integer a(5, 2)
Dim As Integer x = 3
a(x, 1) = 123
Dim As String s = "fxm"
Print a(x,1); Tab(50); s
Open CONS For Output As #2
Print #2, a(x,1); Tab(50); s
Close #2
Sleep
Code: Select all
123 fxm
123 fxm
Re: Print vs Print #2, results with TAB different
Flyzone wrote: ↑Apr 19, 2023 0:58 Interesting. But by specifying CONS as output, mine doesn't.
Output:Code: Select all
Dim As Integer a(5, 2) Dim As Integer x = 3 a(x, 1) = 123 Dim As String s = "fxm" Print a(x,1); Tab(50); s Open CONS For Output As #2 Print #2, a(x,1); Tab(50); s Close #2 Sleep
Code: Select all
123 fxm 123 fxm
Yes, now I see the behavior.
@Jeff,
Using 'Open CONS For Output' to 'Print #' to console:
Tab(x) seems to be always interpreted as a ',' (printing should take place at the next 14 column boundary).
Re: Print vs Print #2, results with TAB different
OK. I would be interested to know if/when there might be a resolution, or, if I should just work around it. Thanks for looking, I'm not under any kind of time pressure.
Re: Print vs Print #2, results with TAB different
An alternative could be:
Code: Select all
Dim As Integer a(5, 2)
Dim As Integer x = 3
a(x, 1) = 123
Dim As String s = "fxm"
Print a(x,1); Tab(50); s
Open scrn For Output As #2
Print #2, a(x,1); tab(50); s
Close #2
Sleep
Re: Print vs Print #2, results with TAB different
Open cons, err and pipe all marks the opened file as a pipe, so tab(anynumber) just does what print , does. (PAD is what the , does in Print)https://github.com/freebasic/fbc/commit/8b8ec8263efea9a87f65617c3abfb632336a125c wrote: mjs committed on Sep 4, 2005
More TAB() fixes ... TAB also works when using "normal" file I/O but will be translated to PAD when using stdout/stderr (cons, err, pipe)
If you redirect the exe output to a file,
Print a(x,1); Tab(50); s
doesn't have any spaces but the Open Cons one does, so perhaps the Tab for cons is on purpose considering its output is consistent.
Re: Print vs Print #2, results with TAB different
I doubt it. Consistent to itself? There is nothing in the doc that I can find that would explain that behavior and the inconsistency with other output formats seems illogical (at least to me). I would think a goal would be to avoid device dependent formatting if possible.... perhaps the Tab for cons is on purpose considering its output is consistent.
Re: Print vs Print #2, results with TAB different
I see that open scrn writes to a graphics screen if there is one or the console if there is not.
So it isn't a very good alternative.
Although from the help file:
Description
This command opens the console for both input and output as a file, allowing to read/write from/to it with normal file commands.
So I was a bit confused, and should have tested out open scrn + graphics screen.
In view of that then , until tab gets looked at for open cons, you could use (as a workaround) the crt printf which always goes to the console.
So it isn't a very good alternative.
Although from the help file:
Description
This command opens the console for both input and output as a file, allowing to read/write from/to it with normal file commands.
So I was a bit confused, and should have tested out open scrn + graphics screen.
In view of that then , until tab gets looked at for open cons, you could use (as a workaround) the crt printf which always goes to the console.
Code: Select all
#include "crt.bi"
screen 12
Dim As Integer a(5, 2)
Dim As Integer x = 3
a(x, 1) = 123
Dim As String s = "fxm"
Printf(!"%d %50s\n",a(x,1), s)
Print a(x,1); tab(50); s
Sleep
Re: Print vs Print #2, results with TAB different
KeyPgOpenScrn → fxm [rewording]
Re: Print vs Print #2, results with TAB different
Does this clarify the different functioning of TAB for Print# to CONS?
Last edited by Flyzone on Apr 20, 2023 17:02, edited 2 times in total.
Re: Print vs Print #2, results with TAB different
No not yet.
I am waiting for a possible feedback from our developer Jeff before finalizing the update for 'Open ...'.
'Open Scrn' supports 'Tab()', not 'Open Cons/Err/Pipe'
But seen from the user, the problem mainly concerns:
- 'Open Cons',
- 'Open Err'.
I am waiting for a possible feedback from our developer Jeff before finalizing the update for 'Open ...'.
'Open Scrn' supports 'Tab()', not 'Open Cons/Err/Pipe'
But seen from the user, the problem mainly concerns:
- 'Open Cons',
- 'Open Err'.
Re: Print vs Print #2, results with TAB different
Here is another workaround for tab
Code: Select all
#define _tab(n) space(n-pos)
Dim As Integer a(5, 2)
Dim As Integer x = 3
a(x, 1) = 123
Dim As String s = "fxm"
Print a(x,1); Tab(50); s
Open CONS For Output As #2
Print #2, a(x,1); _Tab(50); s
Close #2
Open CONS For Output As #2
print "Press any key";_tab(20);"Goodbye"
close #2
Sleep
Re: Print vs Print #2, results with TAB different
At the moment I align the documentation of 'Open Cons/Err' to the current behavior:
- KeyPgOpenCons → fxm [added the output behavior if using TAB]
- KeyPgOpenErr → fxm [added the output behavior if using TAB]